{"id":24493055,"url":"https://github.com/open-node/memoried","last_synced_at":"2025-03-15T03:29:52.659Z","repository":{"id":17962626,"uuid":"20952947","full_name":"open-node/memoried","owner":"open-node","description":"js memory cache, function, object, string","archived":false,"fork":false,"pushed_at":"2014-06-24T23:18:41.000Z","size":136,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-01-21T19:18:55.025Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/open-node.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-06-18T07:15:11.000Z","updated_at":"2020-05-27T22:47:20.000Z","dependencies_parsed_at":"2022-08-26T20:23:45.464Z","dependency_job_id":null,"html_url":"https://github.com/open-node/memoried","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/open-node%2Fmemoried","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/open-node%2Fmemoried/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/open-node%2Fmemoried/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/open-node%2Fmemoried/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/open-node","download_url":"https://codeload.github.com/open-node/memoried/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243680969,"owners_count":20330152,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-01-21T19:19:00.338Z","updated_at":"2025-03-15T03:29:52.634Z","avatar_url":"https://github.com/open-node.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"## memoried ![npm](https://badge.fury.io/js/memoried.png)\n\njs memory cache, support function (async or sync), object, string base on javascript memory variable, It work browser and node.js platform.\n\n### Installation\n````\n$ [sudo] npm install memoried\n````\n\n\n### Example\n````javascript\nvar memoried = require('memoried');\n````\n\n### API\n\n## memoried\n\n\u003cpre\u003e\nvar memoried = require('memoried');\nmemoried(key, value, life, opts);\n\n// case1 get reture from memory-cache\n// only one argument key, key must be a string\n// return null when cache noexists\nvar res = memoried(key);\n\n// case2 set a value(string, number, object or array) in memory-cache\n// value is not function\n// life is a seconds, cache expired = Date.now() + life * 1000\nmemoried(key, value, 1800);\n\n// case3 memoried one function\n// values is a function\n// life is a seconds, This is expired who memoried function exec return\n// opts optinal\n// opts.bind function exec bind\n// opts.sync sync or async default async\n// when async callback must be\n// function(error, result) {}\n// return memoried function\nmemoriedFn = memoried('key{0}-{1}', function(a, b) {\n  // do some things\n  return Date.now();\n}, 1800, {sync: true});\n\n// each time same result\n// because fn return has been cached\nmemoriedFn(1, 2);\nmemoriedFn(1, 2);\nmemoriedFn(1, 2);\n\n//async function memoried\nfunc = function(a, b, callback) {\n  doSomeThing(function() {\n    callback(error, result);\n  });\n};\n\nmemoriedFn = memoried('func-key{0}-{1}', func, 1800, {sync: false, bind: this});\n\n// each time same result\n// because fn return has been cached\nmemoriedFn(1, 3, function(error, result) {\n  console.log(result);\n});\nmemoriedFn(1, 3, function(error, result) {\n  console.log(result);\n});\nmemoriedFn(1, 3, function(error, result) {\n  console.log(result);\n});\n\n\u003c/pre\u003e\n\n\n### MIT license\nCopyright (c) 2014 13740080@qq.com\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \u0026quot;Software\u0026quot;), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in\nall copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \u0026quot;AS IS\u0026quot;, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\nTHE SOFTWARE.\n\n---\n![docor](https://cdn1.iconfinder.com/data/icons/windows8_icons_iconpharm/26/doctor.png)\nbuilt upon love by [docor](https://github.com/turingou/docor.git) v0.1.3\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fopen-node%2Fmemoried","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fopen-node%2Fmemoried","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fopen-node%2Fmemoried/lists"}