{"id":22021504,"url":"https://github.com/lamansky/cached-function","last_synced_at":"2026-04-13T21:32:35.022Z","repository":{"id":57192536,"uuid":"79891043","full_name":"lamansky/cached-function","owner":"lamansky","description":"[Node.js] Wraps a function and caches its return value for any given set of arguments. When those same arguments are used again, it pulls from the cache.","archived":false,"fork":false,"pushed_at":"2017-01-24T08:41:58.000Z","size":6,"stargazers_count":1,"open_issues_count":0,"forks_count":2,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-10-07T12:00:06.726Z","etag":null,"topics":["cache","function","javascript","memo","memoize","nodejs"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/lamansky.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":"license.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-01-24T08:03:26.000Z","updated_at":"2018-06-30T08:53:19.000Z","dependencies_parsed_at":"2022-08-24T05:21:15.580Z","dependency_job_id":null,"html_url":"https://github.com/lamansky/cached-function","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/lamansky/cached-function","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lamansky%2Fcached-function","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lamansky%2Fcached-function/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lamansky%2Fcached-function/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lamansky%2Fcached-function/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/lamansky","download_url":"https://codeload.github.com/lamansky/cached-function/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lamansky%2Fcached-function/sbom","scorecard":{"id":577710,"data":{"date":"2025-08-11","repo":{"name":"github.com/lamansky/cached-function","commit":"794ade3f2bd93160d110ad776648e75716ea2500"},"scorecard":{"version":"v5.2.1-40-gf6ed084d","commit":"f6ed084d17c9236477efd66e5b258b9d4cc7b389"},"score":3,"checks":[{"name":"Maintained","score":0,"reason":"0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project is \"actively maintained\".","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#maintained"}},{"name":"Code-Review","score":0,"reason":"Found 0/1 approved changesets -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project requires human code review before pull requests (aka merge requests) are merged.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#code-review"}},{"name":"SAST","score":0,"reason":"no SAST tool detected","details":["Warn: no pull requests merged into dev branch"],"documentation":{"short":"Determines if the project uses static code analysis.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#sast"}},{"name":"Packaging","score":-1,"reason":"packaging workflow not detected","details":["Warn: no GitHub/GitLab publishing workflow detected."],"documentation":{"short":"Determines if the project is published as a package that others can easily download, install, easily update, and uninstall.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#packaging"}},{"name":"Pinned-Dependencies","score":-1,"reason":"no dependencies found","details":null,"documentation":{"short":"Determines if the project has declared and pinned the dependencies of its build process.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#pinned-dependencies"}},{"name":"Token-Permissions","score":-1,"reason":"No tokens found","details":null,"documentation":{"short":"Determines if the project's workflows follow the principle of least privilege.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#token-permissions"}},{"name":"Dangerous-Workflow","score":-1,"reason":"no workflows found","details":null,"documentation":{"short":"Determines if the project's GitHub Action workflows avoid dangerous patterns.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#dangerous-workflow"}},{"name":"Binary-Artifacts","score":10,"reason":"no binaries found in the repo","details":null,"documentation":{"short":"Determines if the project has generated executable (binary) artifacts in the source repository.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#binary-artifacts"}},{"name":"CII-Best-Practices","score":0,"reason":"no effort to earn an OpenSSF best practices badge detected","details":null,"documentation":{"short":"Determines if the project has an OpenSSF (formerly CII) Best Practices Badge.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#cii-best-practices"}},{"name":"Security-Policy","score":0,"reason":"security policy file not detected","details":["Warn: no security policy file detected","Warn: no security file to analyze","Warn: no security file to analyze","Warn: no security file to analyze"],"documentation":{"short":"Determines if the project has published a security policy.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#security-policy"}},{"name":"Fuzzing","score":0,"reason":"project is not fuzzed","details":["Warn: no fuzzer integrations found"],"documentation":{"short":"Determines if the project uses fuzzing.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#fuzzing"}},{"name":"Vulnerabilities","score":10,"reason":"0 existing vulnerabilities detected","details":null,"documentation":{"short":"Determines if the project has open, known unfixed vulnerabilities.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#vulnerabilities"}},{"name":"Signed-Releases","score":-1,"reason":"no releases found","details":null,"documentation":{"short":"Determines if the project cryptographically signs release artifacts.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#signed-releases"}},{"name":"License","score":10,"reason":"license file detected","details":["Info: project has a license file: license.txt:0","Info: FSF or OSI recognized license: MIT License: license.txt:0"],"documentation":{"short":"Determines if the project has defined a license.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#license"}},{"name":"Branch-Protection","score":0,"reason":"branch protection not enabled on development/release branches","details":["Warn: branch protection not enabled for branch 'master'"],"documentation":{"short":"Determines if the default and release branches are protected with GitHub's branch protection settings.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#branch-protection"}}]},"last_synced_at":"2025-08-20T18:17:24.893Z","repository_id":57192536,"created_at":"2025-08-20T18:17:24.893Z","updated_at":"2025-08-20T18:17:24.893Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31771832,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-13T20:17:16.280Z","status":"ssl_error","status_checked_at":"2026-04-13T20:17:08.216Z","response_time":93,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["cache","function","javascript","memo","memoize","nodejs"],"created_at":"2024-11-30T06:12:21.554Z","updated_at":"2026-04-13T21:32:34.993Z","avatar_url":"https://github.com/lamansky.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# cached-function\n\nA [Node.js](https://nodejs.org/en/) module that wraps a function and caches its return value for any given set of arguments. When those same arguments are used again, it pulls from the cache.\n\n* Cached values can be cleared manually or can be configured to expire automatically.\n* In addition to caching regular functions, the module can also cache class methods and getters.\n\n## Installation\n\n```\nnpm install cached-function --save\n```\n\n## Usage Examples\n\n```javascript\nconst CachedFunction = require('cached-function')\n\nfunction downloadData() {\n  console.log('Downloading...')\n  // Do the download\n  return 'data'\n}\n\n// Returns 'data' and outputs \"Downloading...\"\nCachedFunction(downloadData)()\n\n// Returns 'data' but no console output\nCachedFunction(downloadData)()\n```\n\nIt caches the return value for any given set of arguments:\n\n```javascript\nconst CachedFunction = require('cached-function')\nlet add = CachedFunction((a, b) =\u003e a + b)\nadd(2, 2) // 4\nadd(2, 2) // returns 4 from the cache\n```\n\n### Class Methods\n\nYou can easily modify a prototype to cache a particular method for all instantiated objects:\n\n```javascript\nconst CachedFunction = require('cached-function')\n\nclass TestClass {\n  constructor (value) {\n    this.value = value\n  }\n\n  data (suffix) {\n    console.log('The data method was called')\n    return this.value + suffix\n  }\n}\n\n// Cache the data method\nTestClass.prototype.data = CachedFunction(TestClass.prototype.data)\n\nconst test = new TestClass('value')\ntest.data(123) // returns 'value123' and logs to the console\ntest.data(123) // returns 'value123' but does NOT log to the console\nCachedFunction.clearCache(test, 'data', [123]) // clears the cached return value\ntest.data(123) // returns 'value123' and logs to the console\n```\n\n### Property Getters\n\nThe `cacheGetter()` function makes it easy to implement caching on a property getter:\n\n```javascript\nconst CachedFunction = require('cached-function')\n\nclass TestClass {\n  constructor (value) {\n    this.value = value\n  }\n\n  get data () {\n    console.log('The data getter was called')\n    return this.value\n  }\n}\n\nCachedFunction.cacheGetter(TestClass, 'data', {ttl: 5000})\n\nconst test = new TestClass('value')\ntest.data // returns 'value' and logs to the console\ntest.data // returns 'value' but does NOT log to the console\nCachedFunction.clearCache(test, 'data') // clears the cached return value\ntest.data // returns 'value' and logs to the console\n```\n\n### Manual Cache Clearing\n\nThe `clearCache()` function can be used to flush the cache manually.\n\n```javascript\nconst CachedFunction = require('cached-function')\nlet add = CachedFunction((a, b) =\u003e a + b)\n\nadd(2, 2) // 4\nadd(2, 2) // returns 4 from the cache\n\nadd(5, 5) // 10\nadd(5, 5) // returns 10 from the cache\n\n// Clears the cached return value for the given arguments:\nCachedFunction.clearCache(add, [2, 2])\n\nadd(2, 2) // recalculates: 4\n\nadd(5, 5) // still cached: 10\n```\n\n### Automatic Cache Expiry\n\nCached return values can be set to expire after a given number of milliseconds. After a value expires, future calls with those arguments will trigger the underlying function once again.\n\n```javascript\n// Each cached return value will have a lifetime of 10 seconds.\nfunc = CachedFunction(func, {ttl: 10000})\n```\n\n### Argument Match Modes\n\nBy default, the `CachedFunction` will return a cached return value for a given set of arguments only if those arguments are identical. But if you want, you can disable strict-match mode and can compare arguments by their serialization.\n\n```javascript\nconst CachedFunction = require('cached-function')\n\nfunction callback (stringArg, arrayArg) {\n  console.log('Function called')\n}\n\nconst strict = CachedFunction(callback) // Default behavior\n\nstrict('test', [1, 2, 3]) // Logs to the console\nstrict('test', [1, 2, 3]) // Still logs to the console. The cache is not invoked because it's technically a different array.\n\nconst loose = CachedFunction(callback, {strictArgMatch: false})\n\nloose('test', [1, 2, 3]) // Logs to the console\nloose('test', [1, 2, 3]) // Doesn't log to the console. Pulls from the cache, because the array's serialization is identical.\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flamansky%2Fcached-function","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flamansky%2Fcached-function","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flamansky%2Fcached-function/lists"}