Registry / storage / cachette

cachette

JSON →
library6.0.2jsnpmunverified

A resilient caching library for Node.js (version 6.0.2, latest) that supports concurrent requests through local in-memory cache or Redis. Designed for internal use at Unito, it is undocumented but ships with TypeScript source code. Key differentiators include built-in concurrency handling to avoid thundering herd problems, a simple WriteThroughCache interface, and support for custom TTLs. Requires Node >=20 and npm >=10. Not recommended for production use outside of Unito due to lack of documentation and potential instability.

npm install cachette
INSTALL
IMPORT
SIG · CACHETTE
C
cachette
storagejavascriptv6.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.

WriteThroughCache
✓ import { WriteThroughCache } from 'cachette'
✗ const { WriteThroughCache } = require('cachette')
ESM imports are preferred, but CommonJS require also works (library provides both ESM and CJS). TypeScript types are bundled.
Cachette
✓ import { Cachette } from 'cachette'
✗ const Cachette = require('cachette')
Cachette is a named export. CommonJS require would need { Cachette }.
CacheOptions
✓ import type { CacheOptions } from 'cachette'
✗ import { CacheOptions } from 'cachette'
CacheOptions is a TypeScript type, so use 'import type' to avoid runtime errors.

This shows how to initialize a WriteThroughCache with a Redis URL, define a fetch function, and use getOrFetchValue to cache results with TTL, demonstrating concurrency handling.

import { WriteThroughCache } from 'cachette'; const redisUrl = process.env.REDIS_URL ?? ''; const cache = new WriteThroughCache(redisUrl); async function fetchUrl(url: string): Promise<string> { console.log('fetching', url); const response = await fetch(url); console.log('fetched', url); return response.text(); } async function fetchUrlCached(url: string): Promise<string> { const fetchFunction = () => fetchUrl(url); return cache.getOrFetchValue(url, 600, fetchFunction); } fetchUrlCached('https://example.com').then(() => console.log('first call returned')); setTimeout(() => { fetchUrlCached('https://example.com').then(() => console.log('second call returned')); }, 100);
Debug
Known issues
gotchaThe library is undocumented and intended only for internal Unito use. Expect breaking changes with no warning.
fix
Do not use in production applications unless you are willing to maintain your own fork.
affects: >=6.0.0
breakingNode.js >=20 is required. Older Node versions (18, 16) are not supported.
fix
Upgrade to Node.js 20 or later.
affects: >=6.0.0
gotchaIf REDIS_URL is not provided, the WriteThroughCache constructor will fail silently or behave unexpectedly.
fix
Always provide a valid Redis URL or catch instantiation errors.
affects: >=6.0.0
deprecatedgetOrFetchValue method may be deprecated in future versions in favor of a more flexible API.
fix
Monitor the changelog for API changes.
affects: >=6.0.0
Errors
Common errors & fixes
TypeError: Class constructor WriteThroughCache cannot be invoked without 'new'
Using WriteThroughCache without 'new' keyword.
fix
const cache = new WriteThroughCache(url);
Error: Redis connection failed: connect ECONNREFUSED 127.0.0.1:6379
Redis server is not running or unreachable.
fix
Ensure Redis is running on localhost:6379 or provide a different REDIS_URL.
TypeError: cache.getOrFetchValue is not a function
Importing an older version that does not have getOrFetchValue or using a CommonJS import incorrectly.
fix
Use version >=6.0.0 and import { WriteThroughCache } from 'cachette'.
Upgrade
Version history
6.0.2latest on npm
Audit
Dependencies
redisoptionaloptional Redis backend; if not provided, falls back to local cache
Agent activity
30 hits · last 30 days
node
30
Resources
cachette — npm install cachette · libregistry