{"id":46679,"library":"ttl-cache","title":"ttl-cache","description":"Simple in-memory object cache with per-item TTL (time-to-live) expiry. Version 1.0.2 is the latest stable release, with infrequent updates. Key differentiators: lightweight, zero dependencies, simple API. Suitable for small-scale caching needs where a full-featured cache like node-cache or lru-cache is overkill.","status":"active","version":"1.0.2","language":"javascript","source_language":"en","source_url":"git://github.com/norganna/node-ttl-cache","tags":["javascript","memory","cache","ttl","expiry"],"install":[{"cmd":"npm install ttl-cache","lang":"bash","label":"npm"},{"cmd":"yarn add ttl-cache","lang":"bash","label":"yarn"},{"cmd":"pnpm add ttl-cache","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"Package exports a single constructor function. ESM import is the default export.","wrong":"const ttlCache = require('ttl-cache')","symbol":"default","correct":"import TTLCache from 'ttl-cache'"},{"note":"Named import is incorrect; the package does not export a named class.","wrong":"import { TTLCache } from 'ttl-cache'","symbol":"TTLCache","correct":"import TTLCache from 'ttl-cache'"},{"note":"Methods are on the instance, not static, despite the package's all-caps naming convention.","wrong":"TTLCache.get('key')","symbol":"instance methods","correct":"const cache = new TTLCache({ ttl: 60 }); cache.get('key'); cache.set('key', value);"}],"quickstart":{"code":"import TTLCache from 'ttl-cache';\n\nconst cache = new TTLCache({ ttl: 60 }); // items expire after 60 seconds\n\n// Set a value\ncache.set('greeting', 'Hello, world!');\n\n// Get a value\nconsole.log(cache.get('greeting')); // 'Hello, world!'\n\n// Wait for expiration\nsetTimeout(() => {\n  console.log(cache.get('greeting')); // undefined (expired)\n}, 61000);","lang":"typescript","description":"Creates a TTL cache with 60-second expiry, sets and retrieves a value, then shows expiration after timeout."},"warnings":[{"fix":"Pass TTL in seconds (e.g., 300 for 5 minutes).","message":"The `ttl` option is in seconds, not milliseconds.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Manually call `cache.purge()` to remove expired items proactively.","message":"No built-in eviction for expired items; they are only removed on access.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Install @types/ttl-cache or define your own types.","message":"The package does not support TypeScript type definitions.","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"search_vec":"'1.0.2':21 'api':36 'cach':3,9,42,49,53,57,62 'depend':34 'differenti':31 'expiri':19,64 'featur':48 'full':47 'full-featur':46 'in-memori':5 'infrequ':28 'item':13 'javascript':60 'key':30 'latest':24 'lightweight':32 'like':50 'live':18 'lru':56 'lru-cach':55 'memori':7,61 'need':43 'node':52 'node-cach':51 'object':8 'overkil':59 'per':12 'per-item':11 'releas':26 'scale':41 'simpl':4,35 'small':40 'small-scal':39 'stabl':25 'suitabl':37 'time':16 'time-to-l':15 'ttl':2,14,63 'ttl-cach':1 'updat':29 'version':20 'zero':33","created_at":"2026-06-07T13:01:06.216948+00:00","updated_at":"2026-06-07T13:01:06.216948+00:00","problems":[{"fix":"Run `npm install ttl-cache` or `yarn add ttl-cache`.","cause":"Package not installed correctly (maybe missing from node_modules).","error":"Cannot find module 'ttl-cache'"},{"fix":"Use import TTLCache from 'ttl-cache'.","cause":"Incorrect import (e.g., imported { TTLCache } instead of export default).","error":"TypeError: cache.get is not a function"},{"fix":"Set a positive ttl value in constructor options.","cause":"Item expired immediately due to TTL=0.","error":"undefined is returned for an item that was just set"}],"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/norganna/node-ttl-cache","github":"git://github.com/norganna/node-ttl-cache","docs":null,"changelog":null,"pypi":null,"npm":"ttl-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}}