Registry / database / cachai

cachai

JSON →
library1.0.2jsnpmunverified

cachai is an LRU cache for Node.js, forked from jscache and loosely based on ASP.NET's Cache. Version 1.0.2 is the latest stable release, though the package appears to be in maintenance mode with no recent updates. It provides caching options including absolute expiration, sliding expiration, priority, and a purge callback. Compared to alternatives like lru-cache or node-cache, it offers a more feature-rich API inspired by ASP.NET, but lacks modern ESM support and TypeScript typings.

npm install cachai
INSTALL
IMPORT
SIG · CACHAI
C
cachai
databasejavascriptv1.0.2
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
const Cache = require('cachai')
import Cache from 'cachai' (not ESM-compatible)
Package uses CommonJS only; no default export for ESM.
Cache.Priority.LOW
const low = Cache.Priority.LOW
const low = require('cachai').LOW
Priority constants are nested under Cache.Priority.
cache.setItem()
cache.setItem('key', value, { expirationAbsolute: new Date(), expirationSliding: 60, priority: Cache.Priority.NORMAL, onPurge: (k, v) => {} })
cache.set('key', value) (no 'set' method)
Method name is setItem, not set.

Demonstrates basic usage: create a cache with max size, set/get items with sliding expiration and priority, retrieve stats, remove items, and clear.

const Cache = require('cachai'); const cache = new Cache(100); // max 100 items // add item with sliding expiration of 60 seconds cache.setItem('user-1', { name: 'Alice' }, { expirationSliding: 60, priority: Cache.Priority.HIGH }); // retrieve item const user = cache.getItem('user-1'); console.log(user); // { name: 'Alice' } // cache stats console.log(cache.stats()); // { hits: 1, misses: 0 } // remove item const removed = cache.removeItem('user-1'); // clear all cache.clear();
Debug
Known issues
deprecatedPackage is no longer actively maintained. Consider using lru-cache or node-cache instead.
fix
Migrate to a maintained alternative like lru-cache (npm install lru-cache).
affects: *
gotchaMethods use setItem/getItem/removeItem naming convention, not set/get/del. New users often call nonexistent methods.
fix
Use setItem (add), getItem (retrieve), removeItem (delete).
affects: *
gotchaexpirationAbsolute must be a Date object; passing a string or number will be ignored without warning.
fix
Always pass a Date: { expirationAbsolute: new Date('2025-12-31') }
affects: *
gotchaPriority constants are nested under Cache.Priority; direct properties don't exist.
fix
Use Cache.Priority.LOW, Cache.Priority.NORMAL, Cache.Priority.HIGH.
affects: *
gotchasize() is a method, not a property. Calling cache.size returns undefined.
fix
Use cache.size() with parentheses.
affects: *
Errors
Common errors & fixes
TypeError: cache.set is not a function
Method is called setItem, not set.
fix
Use cache.setItem(key, value, options).
TypeError: cache.size is not a function
size is a method, not a property.
fix
Use cache.size()
TypeError: Cache is not a constructor
Using import instead of require; package does not support ESM.
fix
Use const Cache = require('cachai');
Upgrade
Version history
1.0.2latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
10 hits · last 30 days
node
8
OpenAI (training)
1
Resources
packagecachai
cachai — npm install cachai · libregistry