{"id":45391,"library":"memoize-cache-decorator","title":"memoize-cache-decorator","description":"TypeScript decorator for memoizing class methods and getters with cache expiration and clearing support. Version 2.1.0, actively maintained. Supports Node.js and browsers. Differentiators: built-in TTL (time-to-live), two-level cache clearing (method-level and instance-level), custom resolver function, and TypeScript-first design. Lower overhead than libraries like lodash.memoize because it uses decorator syntax and integrates with class-based architecture. Can memoize async, static, and getter functions. Requires TypeScript >4.x and experimentalDecorators.","status":"active","version":"2.1.0","language":"javascript","source_language":"en","source_url":"https://github.com/edwinm/memoize-cache-decorator","tags":["javascript","front-end","memoize","decorator","cache","clear","reset","timeout","ttl","typescript"],"install":[{"cmd":"npm install memoize-cache-decorator","lang":"bash","label":"npm"},{"cmd":"yarn add memoize-cache-decorator","lang":"bash","label":"yarn"},{"cmd":"pnpm add memoize-cache-decorator","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"The package exports a named export 'memoize'. Default import is incorrect. Also, must be used as a decorator on class methods or getters.","wrong":"import memoize from 'memoize-cache-decorator'","symbol":"memoize","correct":"import { memoize } from 'memoize-cache-decorator'"},{"note":"The function to clear cache for a specific memoized function is named 'clearFunction', not 'clear'.","wrong":"import { clear } from 'memoize-cache-decorator'","symbol":"clearFunction","correct":"import { clearFunction } from 'memoize-cache-decorator'"},{"note":"Used to clear all memoized caches for an instance of a class.","wrong":"","symbol":"clearInstance","correct":"import { clearInstance } from 'memoize-cache-decorator'"}],"quickstart":{"code":"import { memoize, clearFunction, clearInstance } from 'memoize-cache-decorator';\n\nclass Example {\n  @memoize({ ttl: 5000 })\n  expensiveCalculation(n: number): number {\n    console.log('Calculating...');\n    return n * 2;\n  }\n}\n\nconst example = new Example();\nconsole.log(example.expensiveCalculation(5)); // Calculating... 10\nconsole.log(example.expensiveCalculation(5)); // 10 (cached)\n\n// Clear cache for this method on this instance\nclearFunction(example.expensiveCalculation);\nconsole.log(example.expensiveCalculation(5)); // Calculating... 10\n\n// Or clear all memoized caches on the instance\nclearInstance(example);\nconsole.log(example.expensiveCalculation(5)); // Calculating... 10","lang":"typescript","description":"Demonstrates basic memoization with TTL, then clearing cache for a specific function and for the entire instance."},"warnings":[{"fix":"Add \"experimentalDecorators\": true to tsconfig.json, or consider using a different library if you require native ECMAScript decorators.","message":"Decorators require experimentalDecorators: true in tsconfig or use of TypeScript 5.x with decorators stage 3 support (not compatible).","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Update package name from 'memoize-decorator' to 'memoize-cache-decorator' in package.json and imports.","message":"Since v2.0.0, the package moved from 'memoize-decorator' to 'memoize-cache-decorator'. Old package is deprecated and may have breaking differences.","severity":"deprecated","affected_versions":">=2.0.0"},{"fix":"Wrap the function in a class method or use a different memoization approach for standalone functions.","message":"The memoize decorator can only be used on class methods or getters, not on functions or arrow functions.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"If you need a shared cache across instances, consider using a static method or a different caching strategy.","message":"The cache is per-instance. Different instances of the same class have separate caches.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Ensure your async methods are called after the first promise resolves, or implement a queuing mechanism.","message":"When using with async methods, the returned promise is cached, not the resolved value. Calling the method multiple times before the first resolves may cause multiple executions.","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"search_vec":"'2.1.0':20 '4':83 'activ':21 'architectur':73 'async':76 'base':72 'browser':26 'built':29 'built-in':28 'cach':3,14,39,93 'class':9,71 'class-bas':70 'clear':17,40,94 'custom':48 'decor':4,6,65,92 'design':55 'differenti':27 'end':90 'experimentaldecor':86 'expir':15 'first':54 'front':89 'front-end':88 'function':50,80 'getter':12,79 'instanc':46 'instance-level':45 'integr':68 'javascript':87 'level':38,43,47 'librari':59 'like':60 'live':35 'lodash.memoize':61 'lower':56 'maintain':22 'memoiz':2,8,75,91 'memoize-cache-decor':1 'method':10,42 'method-level':41 'node.js':24 'overhead':57 'requir':81 'reset':95 'resolv':49 'static':77 'support':18,23 'syntax':66 'time':33 'time-to-l':32 'timeout':96 'ttl':31,97 'two':37 'two-level':36 'typescript':5,53,82,98 'typescript-first':52 'use':64 'version':19 'x':84","created_at":"2026-06-07T12:54:47.510636+00:00","updated_at":"2026-06-07T12:54:47.510636+00:00","problems":[{"fix":"Ensure you are using the decorator inside a TypeScript class (or with proper Babel decorator transform) and that the import is correct.","cause":"Trying to use the decorator on a non-class function or in a wrong environment (e.g., plain JS without transpilation).","error":"TypeError: Class extends value undefined is not a constructor or null"},{"fix":"For Node: npm install memoize-cache-decorator. For Deno: import { memoize } from 'jsr:@edwinm/memoize-decorator@2'","cause":"Package not installed or imported incorrectly in Deno (should use jsr import).","error":"Cannot find module 'memoize-cache-decorator'"},{"fix":"Use: import { memoize } from 'memoize-cache-decorator'","cause":"Attempting default import instead of named import.","error":"Property 'memoize' does not exist on type 'typeof import(\"memoize-cache-decorator\")'"}],"ecosystem":"npm","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":null,"cli_version":null,"type":"library","homepage":"https://github.com/edwinm/memoize-cache-decorator#readme","github":"https://github.com/edwinm/memoize-cache-decorator","docs":null,"changelog":null,"pypi":null,"npm":"memoize-cache-decorator","openapi_spec":null,"status_page":null,"smithery":null,"categories":["development"],"base_url":null,"auth_type":null,"provenance":{"verified_status":null,"verified_at":null,"last_verified":"2026-06-07","next_check":"2026-09-05","install_tag":null}}