Registry / storage / abstract-cache

abstract-cache

JSON →
library1.0.1jsnpmunverified

abstract-cache v1.0.1 provides a common interface for multiple caching strategies, inspired by Catbox. It allows swapping between in-memory, Redis, MongoDB, and other backends via a simple driver configuration. Unlike Catbox, it supports both callback and async/await patterns, and accepts pre-established connections. Clients like abstract-cache-redis and abstract-cache-mongo exist. The built-in in-memory LRU cache is suitable for development only. Release cadence is low; maintenance mode expected.

npm install abstract-cache
INSTALL
IMPORT
SIG · ABSTRACT-CACHE
A
abstract-cache
storagejavascriptv1.0.1
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.

default
import cache from 'abstract-cache'
const cache = require('abstract-cache')
Default export is a factory function. CJS require works but ESM import is preferred for modern code.
memclient
import { memclient } from 'abstract-cache'
const memclient = require('abstract-cache').memclient
Named export for the in-memory client factory.
factory
import cache from 'abstract-cache'; const client = cache({ useAwait: true })
Factory accepts object with useAwait, driver, or client.

Creates an in-memory cache client with async/await support, sets and retrieves a string value.

import cache from 'abstract-cache'; const client = cache({ useAwait: true }); async function example() { await client.set('greeting', 'Hello, world!', 1000); const value = await client.get('greeting'); console.log(value.item); } example().catch(console.error);
Debug
Known issues
deprecatedThe default in-memory cache is not recommended for production.
fix
Use a proper adapter like abstract-cache-redis in production.
affects: >=0.0.0
gotchaIf useAwait is false (default), all methods require a callback. Missing callback causes silent errors.
fix
Set useAwait: true or provide a callback to each method.
affects: >=1.0.0
gotchaThe key parameter can be either a string or an object {id, segment}. Strategies may differ in how they handle segments.
fix
Always read the specific strategy's documentation for key format.
affects: >=1.0.0
deprecatedThis package is in maintenance mode; no new features or adapters are expected.
fix
Consider newer alternatives like Catbox or keyv.
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: client.get is not a function
Attempting to use the cache factory return without calling the factory (e.g., import cache from 'abstract-cache' then cache.get(...) instead of cache({...}).get(...)).
fix
const client = cache({ useAwait: true }); client.get('key')
Error: driver.name is required
Passing driver without a name property.
fix
Provide driver: { name: 'abstract-cache-redis', options: {} }
TypeError: callback is not a function
Omitting callback when useAwait is false.
fix
Set useAwait: true or provide a callback as the last argument.
Upgrade
Version history
1.0.1latest on npm
Audit
Dependencies
abstract-cache-redisoptionaloptional Redis client driver
abstract-cache-mongooptionaloptional MongoDB client driver
Agent activity
55 hits · last 30 days
node
49
Resources
abstract-cache — npm install abstract-cache · libregistry