{"id":46680,"library":"ttl-cache-js","title":"ttl-cache-js","description":"A simple TTL-based in-memory cache library for Node.js (v1.1.1, 5+ years old). Provides get/set/del/has/size/clear with optional TTL in milliseconds. Minimal dependencies; no async, no events, no size limits. Slower than `node-cache` or `lru-cache`; primarily a teaching example. Not actively maintained (last commit 2018).","status":"maintenance","version":"1.1.1","language":"javascript","source_language":"en","source_url":"https://github.com/Thommee/ttl-cache-js","tags":["javascript","cache","ttl","node"],"install":[{"cmd":"npm install ttl-cache-js","lang":"bash","label":"npm"},{"cmd":"yarn add ttl-cache-js","lang":"bash","label":"yarn"},{"cmd":"pnpm add ttl-cache-js","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"CJS-only; no ESM or default export. Must use require().","wrong":"import Cache from 'ttl-cache-js'","symbol":"Cache","correct":"const Cache = require('ttl-cache-js')"},{"note":"Both work but library returns a factory; new Cache() also returns a new instance via internal fallback.","wrong":"const cache = new Cache()","symbol":"cache instance","correct":"const cache = Cache()"},{"note":"No TypeScript definitions; types are not shipped.","wrong":"import { Cache } from 'ttl-cache-js'","symbol":"type imports","correct":"no type exports"}],"quickstart":{"code":"const Cache = require('ttl-cache-js');\nconst cache = Cache();\ncache.set('greeting', 'Hello', 60000);\nconsole.log(cache.get('greeting')); // 'Hello'\nsetTimeout(() => console.log(cache.get('greeting', 'expired')), 60001); // 'expired'\ncache.del('greeting');\nconsole.log(cache.has('greeting')); // false","lang":"javascript","description":"Basic usage: create cache, set key with 60s TTL, get value, wait for expiry, delete key, and check existence."},"warnings":[{"fix":"Convert seconds to ms: set(key, val, seconds * 1000)","message":"TTL is in milliseconds, not seconds.","severity":"gotcha","affected_versions":">=0.0.0"},{"fix":"Chain with separate calls: cache.set('a', 1); cache.set('b', 2);","message":"set() returns the value, not the cache instance (no chaining).","severity":"gotcha","affected_versions":">=0.0.0"},{"fix":"Use dynamic import() with .mjs wrapper or switch to lru-cache.","message":"No ES module support; will break in Node ESM contexts.","severity":"deprecated","affected_versions":">=0.0.0"}],"env_vars":null,"search_vec":"'2018':55 '5':18 'activ':51 'async':31 'base':9 'cach':3,13,41,45,57 'commit':54 'depend':29 'event':33 'exampl':49 'get/set/del/has/size/clear':22 'in-memori':10 'javascript':56 'js':4 'last':53 'librari':14 'limit':36 'lru':44 'lru-cach':43 'maintain':52 'memori':12 'millisecond':27 'minim':28 'node':40,59 'node-cach':39 'node.js':16 'old':20 'option':24 'primarili':46 'provid':21 'simpl':6 'size':35 'slower':37 'teach':48 'ttl':2,8,25,58 'ttl-base':7 'ttl-cache-j':1 'v1.1.1':17 'year':19","created_at":"2026-06-07T13:01:06.281226+00:00","updated_at":"2026-06-07T13:01:06.281226+00:00","problems":[{"fix":"Use `const cache = Cache()` without `new`.","cause":"Attempting to use `new Cache()` in a context where Cache is not a constructor (factory call works but new fails if library doesn't handle it).","error":"TypeError: Cache is not a constructor"},{"fix":"Run `npm install ttl-cache-js` and use `require('ttl-cache-js')`.","cause":"Missing npm install or incorrect path (ESM import).","error":"Cannot find module 'ttl-cache-js'"},{"fix":"Ensure you call `Cache()` or `new Cache()` to get an instance.","cause":"Instance not created; imported the raw module instead of calling it.","error":"cache.get is not a function"}],"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/Thommee/ttl-cache-js#readme","github":"https://github.com/Thommee/ttl-cache-js","docs":null,"changelog":null,"pypi":null,"npm":"ttl-cache-js","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}}