Registry / storage / dw-cache

dw-cache

JSON →
library0.0.120jsnpmunverified

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.

npm install dw-cache
INSTALL
IMPORT
SIG · DW-CACHE
D
dw-cache
storagejavascriptv0.0.120
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

Cache
✓ import { Cache } from 'dw-cache'
✗ import Cache from 'dw-cache'
Named export since the package ships TypeScript types. Default import will fail.
Cache (CommonJS)
✓ const { Cache } = require('dw-cache')
✗ const Cache = require('dw-cache')
CommonJS requires destructuring. Direct require returns the module, not the class.
CacheOptions (type)
✓ import type { CacheOptions } from 'dw-cache'
✗ import { CacheOptions } from 'dw-cache'
CacheOptions is a type-only export. Use import type to avoid bundler issues in TypeScript.

Demonstrates basic cache operations: construction with limit, get/set/has/del, iteration over keys in MRU order, and clear.

import { Cache } from 'dw-cache'; // Create a cache with a limit of 1000 entries const cache = new Cache({ limit: 1000 }); // Set and get values cache.set('key1', 'value1'); console.log(cache.get('key1')); // 'value1' // Check existence and deletion console.log(cache.has('key1')); // true cache.del('key1'); console.log(cache.has('key1')); // false // Iterate over keys (order is from most recently used to least recently used) cache.set('a', 1); cache.set('b', 2); for (const key of cache) { console.log(key, cache.get(key)); } // Output: b 2, a 1 // Clear all entries cache.clear(); console.log(cache.size); // 0
Debug
Known issues
gotchaCache 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.
fix
Always pass a limit > 0: new Cache({ limit: 1000 })
affects: >=0.0.0
deprecatedThe 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.
fix
Watch https://github.com/falsandtru/spica for migration instructions.
affects: >=0.0.120
gotchaThe 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.
fix
Implement your own TTL wrapper or use a different caching library if TTL is required.
affects: >=0.0.0
gotchaIteration 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.
fix
Treat iteration order as informational only; avoid order-dependent algorithms.
affects: >=0.0.0
Errors
Common errors & fixes
Cannot find module 'dw-cache'
Package not installed or import path incorrect.
fix
Run 'npm install dw-cache' and ensure import uses: import { Cache } from 'dw-cache'
TypeError: dw_cache_1.Cache is not a constructor
Attempting to use default import when named export is required.
fix
Change to: import { Cache } from 'dw-cache'
ConstraintError: limit must be a positive integer
Cache created with a limit of 0 or a non-number.
fix
Pass { limit: 1000 } (or any positive integer) to the constructor.
Upgrade
Version history
0.0.120latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
45 hits · last 30 days
node
40
OpenAI (training)
1
Resources
dw-cache — npm install dw-cache · libregistry