{"id":46674,"library":"ts-promise-cache","title":"ts-promise-cache","description":"A TypeScript promise-based loading cache that prevents thundering herds (cache stampede). Version 0.9.0 is the latest stable release. Ships with TypeScript definitions. Low release cadence. Differentiators: configurable TTL (access- or write-based), separate cache for single values, statistics, explicit set method, and customizable rejection handling with optional retry via ts-retry-promise.","status":"active","version":"0.9.0","language":"javascript","source_language":"en","source_url":"https://github.com/normartin/ts-promise-cache","tags":["javascript","promise","cache","typescript"],"install":[{"cmd":"npm install ts-promise-cache","lang":"bash","label":"npm"},{"cmd":"yarn add ts-promise-cache","lang":"bash","label":"yarn"},{"cmd":"pnpm add ts-promise-cache","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"Package is ESM-first and ships TypeScript types. CJS require works but may need .default.","wrong":"const PromiseCache = require('ts-promise-cache')","symbol":"PromiseCache","correct":"import { PromiseCache } from 'ts-promise-cache'"},{"note":"Factory function for caching a single promise. Use named import.","wrong":"const { singlePromiseCache } = require('ts-promise-cache')","symbol":"singlePromiseCache","correct":"import { singlePromiseCache } from 'ts-promise-cache'"},{"note":"CacheConfig is a named export (class), not a default export.","wrong":"import CacheConfig from 'ts-promise-cache'","symbol":"CacheConfig","correct":"import { CacheConfig } from 'ts-promise-cache'"},{"note":"Interface for stats object, useful for type annotations.","wrong":"","symbol":"Stats","correct":"import { Stats } from 'ts-promise-cache'"}],"quickstart":{"code":"import { PromiseCache } from 'ts-promise-cache';\n\nconst cache = new PromiseCache<string>((key) => Promise.resolve(`value for ${key}`));\n\nasync function main() {\n  const value = await cache.get('myKey');\n  console.log(value); // 'value for myKey'\n\n  const stats = cache.stats();\n  console.log(stats.hits, stats.misses);\n}\n\nmain().catch(console.error);","lang":"typescript","description":"Creates a PromiseCache with a loader, retrieves a value, and logs cache statistics."},"warnings":[{"fix":"Set ttl and checkInterval when creating cache to avoid unbounded memory growth.","message":"Default TTL is 'FOREVER', meaning entries never expire unless explicitly configured.","severity":"gotcha","affected_versions":"*"},{"fix":"Override onReject to handle retries or provide fallback values.","message":"Default onReject re-throws the error; rejected promises are not cached (removeRejected: true).","severity":"gotcha","affected_versions":"*"},{"fix":"Ensure loader returns a Promise; for synchronous loads, wrap in Promise.resolve().","message":"The loader is called synchronously with the key argument; async loaders must return a Promise.","severity":"gotcha","affected_versions":"*"},{"fix":"Review the GitHub releases for migration notes.","message":"Version 0.9.0 may have breaking changes from earlier 0.x versions; check changelog.","severity":"breaking","affected_versions":"<0.9.0"}],"env_vars":null,"search_vec":"'0.9.0':19 'access':35 'base':9,39 'cach':4,11,16,41,63 'cadenc':31 'configur':33 'customiz':50 'definit':28 'differenti':32 'explicit':46 'handl':52 'herd':15 'javascript':61 'latest':22 'load':10 'low':29 'method':48 'option':54 'prevent':13 'promis':3,8,60,62 'promise-bas':7 'reject':51 'releas':24,30 'retri':55,59 'separ':40 'set':47 'ship':25 'singl':43 'stabl':23 'stamped':17 'statist':45 'thunder':14 'ts':2,58 'ts-promise-cach':1 'ts-retry-promis':57 'ttl':34 'typescript':6,27,64 'valu':44 'version':18 'via':56 'write':38 'write-bas':37","created_at":"2026-06-07T13:01:04.260309+00:00","updated_at":"2026-06-07T13:01:04.260309+00:00","problems":[{"fix":"import { PromiseCache } from 'ts-promise-cache'","cause":"Importing the wrong export or using CJS incorrectly.","error":"TypeError: PromiseCache is not a constructor"},{"fix":"Update to 0.9.0: npm install ts-promise-cache@latest","cause":"Using an older version before stats was added (pre-0.9.0).","error":"Property 'stats' does not exist on type 'PromiseCache<string>'"},{"fix":"const cachedFn = singlePromiseCache(loader); const value = await cachedFn();","cause":"Using singlePromiseCache incorrectly: it returns a function, not a cache object.","error":"Expected 0 arguments, but got 1"}],"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/normartin/ts-promise-cache#readme","github":"https://github.com/normartin/ts-promise-cache","docs":null,"changelog":null,"pypi":null,"npm":"ts-promise-cache","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}}