{"id":23841796,"url":"https://github.com/playerony/memoize-function","last_synced_at":"2025-10-10T06:13:44.081Z","repository":{"id":51124421,"uuid":"368648234","full_name":"playerony/memoize-function","owner":"playerony","description":"A memoization library that caches all results and supports N arguments with any type.","archived":false,"fork":false,"pushed_at":"2021-05-22T14:54:35.000Z","size":163,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-07-06T12:07:40.667Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"TypeScript","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/playerony.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":"2021-05-18T19:42:03.000Z","updated_at":"2021-07-13T15:06:03.000Z","dependencies_parsed_at":"2022-09-06T14:23:01.914Z","dependency_job_id":null,"html_url":"https://github.com/playerony/memoize-function","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/playerony/memoize-function","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/playerony%2Fmemoize-function","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/playerony%2Fmemoize-function/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/playerony%2Fmemoize-function/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/playerony%2Fmemoize-function/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/playerony","download_url":"https://codeload.github.com/playerony/memoize-function/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/playerony%2Fmemoize-function/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279002964,"owners_count":26083487,"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","status":"online","status_checked_at":"2025-10-10T02:00:06.843Z","response_time":62,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"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":[],"created_at":"2025-01-02T18:02:22.509Z","updated_at":"2025-10-10T06:13:44.058Z","avatar_url":"https://github.com/playerony.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# memoize-function\n\n![Lint Check](https://github.com/playerony/memoize-function/workflows/Lint/badge.svg)\n![Test Check](https://github.com/playerony/memoize-function/workflows/Test/badge.svg)\n![Production Build](https://github.com/playerony/memoize-function/workflows/Build/badge.svg)\n![Typecheck Check](https://github.com/playerony/memoize-function/workflows/Typecheck/badge.svg)\n\n\u003e In computing, memoization is an optimization technique used primarily to speed up computer programs by storing the results of expensive function calls and returning the cached result when the same inputs occur again.\n\u003e — Wikipedia\n\nA memoization library that caches all results and supports _N_ arguments with any type.\n\n## Installation\n\n```shell\nnpm install memoize-function --save\n```\n\n## Usage\n\n```js\nconst memoizeFunction = require(\"memoize-function\");\n\nconst factorial = memoizeFunction((value) =\u003e {\n  if (value \u003c= 1) {\n    return 1;\n  }\n\n  return value * factorial(value - 1);\n});\n\nfactorial(50);\nfactorial(20); // Value from cache\n```\n\n### Custom storage\n\nIt is possible to pass a custom storage to be used.\n\n```js\nconst memoized = memoizeFunction(fn, {\n  storage: {\n    store: {},\n    clear() {\n      this.store = {};\n    },\n    remove(key) {\n      delete this.store[key];\n    },\n    set(key, value) {\n      this.store[key] = value;\n    },\n    get(key) {\n      return this.store[key] || null;\n    },\n  },\n});\n```\n\n```js\nclass Storage {\n  store;\n\n  constructor() {\n    this.store = {};\n  }\n\n  clear() {\n    this.store = {};\n  }\n\n  remove(key) {\n    delete this.store[key];\n  }\n\n  get(key) {\n    return this.store[key] || null;\n  }\n\n  set(key, value) {\n    this.store[key] = value;\n  }\n}\n\nconst memoized = memoizeFunction(fn, {\n  storage: new Storage(),\n});\n```\n\nThe custom cache can be a class or an object implementing the following methods:\n\n- `get`\n- `set`\n- `clear`\n- `remove`\n\n### Custom cache key generator\n\nTo use a custom cache key generator:\n\n```js\nconst generateCacheKey = (...args) =\u003e\n  \"my_custom_key_for_each_function_argument\";\n\nconst memoized = memoizeFunction(fn, {\n  generateCacheKey,\n});\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fplayerony%2Fmemoize-function","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fplayerony%2Fmemoize-function","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fplayerony%2Fmemoize-function/lists"}