{"id":46669,"library":"ts-cacheable","title":"ts-cacheable","description":"ts-cacheable (v1.0.19) is a TypeScript library providing decorators for caching Observable and Promise return values from class methods. It uses an in-memory cache by default and supports configurable cache busting, parameter-based cache keys, max age, sliding expiration, and async resolution. The library was originally designed for Angular (as ngx-cacheable) but is now platform-agnostic. It ships with TypeScript type definitions. Release cadence is low; last release was in 2021.","status":"maintenance","version":"1.0.19","language":"javascript","source_language":"en","source_url":"https://github.com/angelnikolov/ts-cacheable","tags":["javascript","typescript"],"install":[{"cmd":"npm install ts-cacheable","lang":"bash","label":"npm"},{"cmd":"yarn add ts-cacheable","lang":"bash","label":"yarn"},{"cmd":"pnpm add ts-cacheable","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Requires tslib for helper functions when using importHelpers in TypeScript","package":"tslib","optional":true}],"imports":[{"note":"ESM-only; CommonJS require may not work as expected in some bundlers. Named export.","wrong":"const { Cacheable } = require('ts-cacheable')","symbol":"Cacheable","correct":"import { Cacheable } from 'ts-cacheable'"},{"note":"PCacheable is for Promise-returning methods. Common mistake is using Cacheable (Observable) on a Promise method.","wrong":"import { Cacheable } from 'ts-cacheable'","symbol":"PCacheable","correct":"import { PCacheable } from 'ts-cacheable'"},{"note":"CacheBuster is a named export, not default. Used to bust caches when a method is called.","wrong":"import CacheBuster from 'ts-cacheable'","symbol":"CacheBuster","correct":"import { CacheBuster } from 'ts-cacheable'"},{"note":"TypeScript type import for configuring Cacheable decorator. No common mistake.","wrong":null,"symbol":"ICacheConfig","correct":"import { ICacheConfig } from 'ts-cacheable'"}],"quickstart":{"code":"import { Cacheable } from 'ts-cacheable';\nimport { Injectable } from '@angular/core';\nimport { HttpClient } from '@angular/common/http';\n\n@Injectable({ providedIn: 'root' })\nexport class UserService {\n  constructor(private http: HttpClient) {}\n\n  @Cacheable()\n  getUsers() {\n    return this.http.get('/users');\n  }\n\n  @Cacheable({\n    maxAge: 30000,\n    slidingExpiration: true\n  })\n  getUser(id: number) {\n    return this.http.get(`/users/${id}`);\n  }\n}\n\n// Usage\nconst service = inject(UserService);\nservice.getUsers().subscribe(); // makes HTTP call\nservice.getUsers().subscribe(); // returns cached result","lang":"typescript","description":"Shows Cacheable decorator on Observable-returning methods with in-memory caching and parameter-based cache keys."},"warnings":[{"fix":"Replace all imports from 'ngx-cacheable' with 'ts-cacheable'.","message":"The package was renamed from ngx-cacheable to ts-cacheable. Projects using the old name will break.","severity":"breaking","affected_versions":">=0.2.0"},{"fix":"Use 'Cacheable' for Observable, 'PCacheable' for Promise. The old 'Cacheable' works for both but is less explicit.","message":"The old decorator name 'Cacheable' is still available but may be deprecated in future versions.","severity":"deprecated","affected_versions":">=1.0.0"},{"fix":"Use PCacheable for Promise-returning methods instead of Cacheable.","message":"Using Cacheable on a Promise-returning method without PCacheable may cause type errors or unexpected behavior.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Set \"experimentalDecorators\": true in tsconfig.json.","message":"Cacheable requires TypeScript's experimentalDecorators to be enabled in tsconfig.json.","severity":"gotcha","affected_versions":">=0.1.0"},{"fix":"If persistence is needed, implement a custom storage strategy using the cacheHasher and ICachePair interface.","message":"The default cache is in-memory only; it does not persist across page reloads.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Clear any persisted in-memory caches after upgrade; they will be rebuilt.","message":"Version 1.0.0 changed the cache key hashing algorithm, breaking existing caches on upgrade.","severity":"breaking","affected_versions":">=0.2.0 <1.0.0"},{"fix":"Test thoroughly and consider using cacheResolver instead for custom cache logic.","message":"The ICacheConfig.shouldCacheDecider is not well documented and its behavior might change.","severity":"deprecated","affected_versions":">=1.0.0"}],"env_vars":null,"search_vec":"'2021':81 'age':44 'agnost':66 'angular':56 'async':48 'base':40 'bust':37 'cach':15,30,36,41 'cacheabl':3,6,60 'cadenc':74 'class':22 'configur':35 'decor':13 'default':32 'definit':72 'design':54 'expir':46 'in-memori':27 'javascript':82 'key':42 'last':77 'librari':11,51 'low':76 'max':43 'memori':29 'method':23 'ngx':59 'ngx-cacheabl':58 'observ':16 'origin':53 'paramet':39 'parameter-bas':38 'platform':65 'platform-agnost':64 'promis':18 'provid':12 'releas':73,78 'resolut':49 'return':19 'ship':68 'slide':45 'support':34 'ts':2,5 'ts-cacheabl':1,4 'type':71 'typescript':10,70,83 'use':25 'v1.0.19':7 'valu':20","created_at":"2026-06-07T13:01:03.754669+00:00","updated_at":"2026-06-07T13:01:03.754669+00:00","problems":[{"fix":"Set \"experimentalDecorators\": true in tsconfig.json and restart the TS server.","cause":"TypeScript configuration missing experimentalDecorators.","error":"Cannot use decorators unless 'experimentalDecorators' is enabled"},{"fix":"Ensure the class is instantiated properly, or use the decorator only on methods within an Angular service or similar DI context.","cause":"Using Cacheable decorator on a method of a class that isn't instantiated via dependency injection (e.g., calling static method or manually instantiated class).","error":"TypeError: Cannot read property 'get' of undefined"},{"fix":"Use PCacheable decorator for Promise-returning methods.","cause":"Using Cacheable on a Promise-returning method instead of PCacheable.","error":"Argument of type 'Observable<...>' is not assignable to parameter of type 'PromiseLike<...>'"},{"fix":"Run 'npm install ts-cacheable' and ensure tsconfig.json includes node_modules in paths or types.","cause":"Package not installed or TypeScript cannot resolve module.","error":"Cannot find module 'ts-cacheable' or its corresponding type declarations."},{"fix":"Avoid calling the same cached method inside itself; use cacheBusterObserver to break recursion.","cause":"Circular cache busting or recursive method call.","error":"Error encountered in cache pipeline for method 'yourMethodName': Maximum call stack size exceeded"}],"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/angelnikolov/ts-cacheable#readme","github":"https://github.com/angelnikolov/ts-cacheable","docs":null,"changelog":null,"pypi":null,"npm":"ts-cacheable","openapi_spec":null,"status_page":null,"smithery":null,"categories":["storage"],"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}}