{"id":44802,"library":"dw-cache","title":"Dual Window Cache (dw-cache)","description":"Dual Window Cache (DWC) is a high-performance constant-time cache algorithm in TypeScript/JavaScript, implemented in the dw-cache npm package at version 0.0.120. It claims the highest engineering hit ratio among general-purpose caching algorithms by using only two lists for low overhead and latency, with resistance to scan, loop, and burst access patterns. Unlike LIRS or TinyLFU, DWC avoids batch processing, linear-time operations, and excessive memory overhead. It ships with TypeScript types and is actively maintained. Recommended for cache sizes above 200 entries (ideally 5,000+) for optimal statistical precision. The package is a standalone implementation of the DWC algorithm, now maintained as part of the spica monorepo.","status":"active","version":"0.0.120","language":"javascript","source_language":"en","source_url":"https://github.com/falsandtru/dw-cache","tags":["javascript","cache","lru","lfu","arc","typescript"],"install":[{"cmd":"npm install dw-cache","lang":"bash","label":"npm"},{"cmd":"yarn add dw-cache","lang":"bash","label":"yarn"},{"cmd":"pnpm add dw-cache","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"Named export since the package ships TypeScript types. Default import will fail.","wrong":"import Cache from 'dw-cache'","symbol":"Cache","correct":"import { Cache } from 'dw-cache'"},{"note":"CommonJS requires destructuring. Direct require returns the module, not the class.","wrong":"const Cache = require('dw-cache')","symbol":"Cache (CommonJS)","correct":"const { Cache } = require('dw-cache')"},{"note":"CacheOptions is a type-only export. Use import type to avoid bundler issues in TypeScript.","wrong":"import { CacheOptions } from 'dw-cache'","symbol":"CacheOptions (type)","correct":"import type { CacheOptions } from 'dw-cache'"}],"quickstart":{"code":"import { Cache } from 'dw-cache';\n\n// Create a cache with a limit of 1000 entries\nconst cache = new Cache({ limit: 1000 });\n\n// Set and get values\ncache.set('key1', 'value1');\nconsole.log(cache.get('key1')); // 'value1'\n\n// Check existence and deletion\nconsole.log(cache.has('key1')); // true\ncache.del('key1');\nconsole.log(cache.has('key1')); // false\n\n// Iterate over keys (order is from most recently used to least recently used)\ncache.set('a', 1);\ncache.set('b', 2);\nfor (const key of cache) {\n  console.log(key, cache.get(key));\n}\n// Output: b 2, a 1\n\n// Clear all entries\ncache.clear();\nconsole.log(cache.size); // 0","lang":"typescript","description":"Demonstrates basic cache operations: construction with limit, get/set/has/del, iteration over keys in MRU order, and clear."},"warnings":[{"fix":"Always pass a limit > 0: new Cache({ limit: 1000 })","message":"Cache limit is enforced strictly; if you set a limit of 0, all entries will be evicted immediately. Ensure limit is a positive integer for meaningful caching.","severity":"gotcha","affected_versions":">=0.0.0"},{"fix":"Watch https://github.com/falsandtru/spica for migration instructions.","message":"The package is being maintained as part of the spica monorepo; future releases will be under a different package name. Monitor the spica repository for upcoming changes.","severity":"deprecated","affected_versions":">=0.0.120"},{"fix":"Implement your own TTL wrapper or use a different caching library if TTL is required.","message":"The cache does not support TTL (time-to-live) out of the box; entries remain until evicted by capacity or explicitly deleted. Do not rely on automatic expiration.","severity":"gotcha","affected_versions":">=0.0.0"},{"fix":"Treat iteration order as informational only; avoid order-dependent algorithms.","message":"Iteration order is from most recently used to least recently used (LRU order). This is not guaranteed across versions; do not rely on the order for critical logic.","severity":"gotcha","affected_versions":">=0.0.0"}],"env_vars":null,"search_vec":"'0.0.120':33 '000':100 '200':96 '5':99 'access':64 'activ':89 'algorithm':20,46,114 'among':41 'arc':127 'avoid':71 'batch':72 'burst':63 'cach':3,6,9,19,28,45,93,124 'claim':35 'constant':17 'constant-tim':16 'dual':1,7 'dw':5,27 'dw-cach':4,26 'dwc':10,70,113 'engin':38 'entri':97 'excess':79 'general':43 'general-purpos':42 'high':14 'high-perform':13 'highest':37 'hit':39 'ideal':98 'implement':23,110 'javascript':123 'latenc':56 'lfu':126 'linear':75 'linear-tim':74 'lir':67 'list':51 'loop':61 'low':53 'lru':125 'maintain':90,116 'memori':80 'monorepo':122 'npm':29 'oper':77 'optim':102 'overhead':54,81 'packag':30,106 'part':118 'pattern':65 'perform':15 'precis':104 'process':73 'purpos':44 'ratio':40 'recommend':91 'resist':58 'scan':60 'ship':83 'size':94 'spica':121 'standalon':109 'statist':103 'time':18,76 'tinylfu':69 'two':50 'type':86 'typescript':85,128 'typescript/javascript':22 'unlik':66 'use':48 'version':32 'window':2,8","created_at":"2026-06-07T12:51:54.637940+00:00","updated_at":"2026-06-07T12:51:54.637940+00:00","problems":[{"fix":"Run 'npm install dw-cache' and ensure import uses: import { Cache } from 'dw-cache'","cause":"Package not installed or import path incorrect.","error":"Cannot find module 'dw-cache'"},{"fix":"Change to: import { Cache } from 'dw-cache'","cause":"Attempting to use default import when named export is required.","error":"TypeError: dw_cache_1.Cache is not a constructor"},{"fix":"Pass { limit: 1000 } (or any positive integer) to the constructor.","cause":"Cache created with a limit of 0 or a non-number.","error":"ConstraintError: limit must be a positive integer"}],"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/falsandtru/dw-cache","github":"https://github.com/falsandtru/dw-cache","docs":null,"changelog":null,"pypi":null,"npm":"dw-cache","openapi_spec":null,"status_page":null,"smithery":null,"categories":["storage","testing"],"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}}