{"id":15608497,"url":"https://github.com/alorel/memoise-decorator","last_synced_at":"2026-02-10T16:31:30.317Z","repository":{"id":34304405,"uuid":"175279421","full_name":"Alorel/memoise-decorator","owner":"Alorel","description":"An ES7 decorator for memoising (caching) a method's response","archived":false,"fork":false,"pushed_at":"2023-12-14T18:42:32.000Z","size":657,"stargazers_count":0,"open_issues_count":3,"forks_count":1,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-04-14T13:44:54.933Z","etag":null,"topics":["babel","decorator","es7","memoise","typescript"],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Alorel.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":".github/CONTRIBUTING.md","funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":".github/CODEOWNERS","security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":["Alorel"],"custom":["https://paypal.me/alorel"]}},"created_at":"2019-03-12T19:04:51.000Z","updated_at":"2023-10-16T16:02:26.000Z","dependencies_parsed_at":"2024-10-03T05:21:17.780Z","dependency_job_id":"673b5a62-d5ac-47b0-9b66-8537eaebfb53","html_url":"https://github.com/Alorel/memoise-decorator","commit_stats":{"total_commits":178,"total_committers":7,"mean_commits":"25.428571428571427","dds":0.5898876404494382,"last_synced_commit":"8e523cf689e2a535b8188546902fe2e45e1d275e"},"previous_names":[],"tags_count":12,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Alorel%2Fmemoise-decorator","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Alorel%2Fmemoise-decorator/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Alorel%2Fmemoise-decorator/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Alorel%2Fmemoise-decorator/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Alorel","download_url":"https://codeload.github.com/Alorel/memoise-decorator/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246194919,"owners_count":20738763,"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":["babel","decorator","es7","memoise","typescript"],"created_at":"2024-10-03T05:21:07.226Z","updated_at":"2026-02-10T16:31:30.273Z","avatar_url":"https://github.com/Alorel.png","language":"TypeScript","funding_links":["https://github.com/sponsors/Alorel","https://paypal.me/alorel"],"categories":[],"sub_categories":[],"readme":"# Memoise decorator\n\nAn ES7 decorator for memoising (caching) a method's response\n\n[![MASTER CI status](https://github.com/Alorel/memoise-decorator/actions/workflows/core.yml/badge.svg)](https://github.com/Alorel/memoise-decorator/actions/workflows/core.yml?query=branch%3Amaster)\n[![NPM badge](https://img.shields.io/npm/v/%40aloreljs/memoise-decorator)](https://www.npmjs.com/package/%40aloreljs/memoise-decorator)\n[![dependencies badge](https://img.shields.io/librariesio/release/npm/%40aloreljs/memoise-decorator)](https://libraries.io/npm/@aloreljs%2Fmemoise-decorator)\n[![Coverage Status](https://coveralls.io/repos/github/Alorel/memoise-decorator/badge.svg)](https://coveralls.io/github/Alorel/memoise-decorator)\n\n-----\n\n# Table of Contents\n\n\u003c!-- START doctoc generated TOC please keep comment here to allow auto update --\u003e\n\u003c!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE --\u003e\n\n- [Installation](#installation)\n- [Compatibility](#compatibility)\n- [Usage](#usage)\n  - [Basic Usage](#basic-usage)\n  - [Custom Cache Key Generator](#custom-cache-key-generator)\n  - [Memoising all method calls disregarding parameters](#memoising-all-method-calls-disregarding-parameters)\n  - [Direct access to the cache](#direct-access-to-the-cache)\n  - [Memoising arbitrary functions](#memoising-arbitrary-functions)\n- [Migrating from v2](#migrating-from-v2)\n\n\u003c!-- END doctoc generated TOC please keep comment here to allow auto update --\u003e\n\n# Installation\n\n    npm install @aloreljs/memoise-decorator\n\n# Compatibility\n\nThe library's only goal is to be compatible with Typescript 5 decorators which, at the time of writing, use the [2022-03 stage 3 decorators proposal](https://2ality.com/2022/10/javascript-decorators.html). The bulk of your inputs' validation is offloaded to Typescript as well.\n\n# Usage\n## Basic Usage\n\n```typescript\nimport {Memoise} from '@aloreljs/memoise-decorator';\n\nclass MyClass {\n  @Memoise()\n  someMethod(a, b, c) {\n  }\n  \n  @Memoise()\n  static someStaticMethod(a, b, c) {\n  }\n}\n```\n\n## Custom Cache Key Generator\n\nThe decorator uses `JSON.stringify` on the method arguments to generate a cache key by default, which should work for\nmost scenarios, but can be inefficient or unusable in others. You can replace it by passing your own cache key\ngenerator to the decorator function. It will be called with the class instance as an argument.\n\nThe function can return anything that's uniquely identifiable in a Map.\n\n```typescript\nimport {Memoise} from '@aloreljs/memoise-decorator';\n\nclass MyClass {\n  constructor() {\n    this.someId = 'foo';\n  }\n  \n  @Memoise(function(this: MyClass, label: string, data: number) {\n    return `${this.someId}:${label}:${data}`;\n  })\n  someMethod(label: string, data: number): void {\n  }\n}\n```\n\n## Memoising all method calls disregarding parameters\n\nThis might be useful for methods that don't accept parameters in the first place.\n\n```javascript\nimport {MemoiseAll} from '@aloreljs/memoise-decorator';\n\nclass MyClass {\n  @MemoiseAll()\n  method() {\n    return 'foo';\n  }\n}\n```\n\n## Direct access to the cache\n\nAfter being called at least once, the method will get a `MEMOISE_CACHE` property containing the cache.\n\n```typescript\nimport {MEMOISE_CACHE, Memoise} from '@aloreljs/memoise-decorator';\n\nclass MyClass {\n  @Memoise()\n  method(a) {\n    return a + 10;\n  }\n}\nconst instance = new MyClass();\ninstance.method(instance.method(1));\nconsole.log(instance.method[MEMOISE_CACHE]!.get(defaultSerialiser(1))); // 11, or our argument of 1 + 10\n```\n\n## Memoising arbitrary functions\n\n```typescript\nimport {memoiseArglessFunction, memoiseFunction} from '@aloreljs/memoise-decorator';\n\nconst fn1 = memoiseArglessFunction(() =\u003e Math.random());\nconst fn2 = memoiseFunction((a, b) =\u003e a + b);\n```\n\n# Migrating from v2\n\n- Instead of `@Memoise.all()` use `@MemoiseAll()`\n- Typings added for `MEMOISE_CACHE`\n- Dropped support for typescript's experimental decorators\n- Added functions exports for memoising arbitrary functions\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falorel%2Fmemoise-decorator","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Falorel%2Fmemoise-decorator","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falorel%2Fmemoise-decorator/lists"}