{"id":24494692,"url":"https://github.com/bwca/package_merry-solutions_memoize-decorator","last_synced_at":"2025-06-12T08:06:32.655Z","repository":{"id":57710595,"uuid":"511389070","full_name":"Bwca/package_merry-solutions_memoize-decorator","owner":"Bwca","description":"A function to decorate methods and memoize their results to speed up further requests done with the same arguments.","archived":false,"fork":false,"pushed_at":"2022-07-08T06:57:57.000Z","size":25,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-05-23T07:51:20.845Z","etag":null,"topics":["decorator","memoization","memoize","memoize-decorator","performance"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","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/Bwca.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-07-07T05:01:40.000Z","updated_at":"2022-07-30T15:55:27.000Z","dependencies_parsed_at":"2022-09-10T22:01:49.570Z","dependency_job_id":null,"html_url":"https://github.com/Bwca/package_merry-solutions_memoize-decorator","commit_stats":null,"previous_names":["bwca/package__merry-solutions__memoize-decorator"],"tags_count":0,"template":false,"template_full_name":"Bwca/template_ts-repo","purl":"pkg:github/Bwca/package_merry-solutions_memoize-decorator","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Bwca%2Fpackage_merry-solutions_memoize-decorator","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Bwca%2Fpackage_merry-solutions_memoize-decorator/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Bwca%2Fpackage_merry-solutions_memoize-decorator/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Bwca%2Fpackage_merry-solutions_memoize-decorator/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Bwca","download_url":"https://codeload.github.com/Bwca/package_merry-solutions_memoize-decorator/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Bwca%2Fpackage_merry-solutions_memoize-decorator/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":259426986,"owners_count":22855555,"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":["decorator","memoization","memoize","memoize-decorator","performance"],"created_at":"2025-01-21T20:16:53.714Z","updated_at":"2025-06-12T08:06:32.627Z","avatar_url":"https://github.com/Bwca.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Memoize Decorator\n\n## Well, what is it?\n\nA function to decorate methods and memoize their results to speed up further requests done with the same arguments.\n\n## How to use it\n\n```bash\nnpm i @merry-solutions/memoize-decorator\n```\n\nThe decorator can accept the following payload:\n\n```typescript\nexport interface MemoizePayload {\n  // The function that will determine a unique id for the provided arguments set, you write iy\n  extractUniqueId: (...args: any[]) =\u003e any;\n  // Pass true if you want to use WeakMap, not that it requires keys to be objects\n  doUseWeakMap?: boolean;\n  // If regular map is used, you can set timeout to clear its contents, optional\n  clearCacheTimeout?: number;\n  // For debug purposes you can pass an exta function for logging all actions\n  debugReporter?: (message: string, state?: Map\u003cany, unknown\u003e | WeakMap\u003cobject, unknown\u003e | unknown) =\u003e void;\n}\n```\n\nNow let's assume there's some class doing some calculations:\n\n```typescript\ninterface CalculationPayload {\n  id: number;\n  someCountdownNumber: number;\n}\n\nclass ObjectCountdownCalculator {\n  public countdown({ someCountdownNumber }: CalculationPayload): number {\n    let count = 0;\n    while (count \u003c someCountdownNumber) {\n      count += 1;\n    }\n    return count;\n  }\n}\n```\n\nAssuming the unique arguments' identifier is the id of the passed object, we could decorate it:\n\n```typescript\nimport { memoize } from '@merry-solutions/memoize-decorator';\n\nclass ObjectCountdownCalculator {\n  @memoize({\n    extractUniqueId: (a: CalculationPayload) =\u003e a.id,\n  })\n  public countdown({ someCountdownNumber }: CalculationPayload): number {\n    let count = 0;\n    while (count \u003c someCountdownNumber) {\n      count += 1;\n    }\n    return count;\n  }\n}\n```\n\nAnd poof! Our method is now leveraging the power of memoization to reduce execution time :)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbwca%2Fpackage_merry-solutions_memoize-decorator","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbwca%2Fpackage_merry-solutions_memoize-decorator","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbwca%2Fpackage_merry-solutions_memoize-decorator/lists"}