Registry / database / cache-manager-sqlite

cache-manager-sqlite

JSON →
library0.2.0jsnpmunverified

An SQLite-based store for node-cache-manager, version 0.2.0. Provides async SQLite caching using the sqlite3 package with support for WAL mode, allowing safe multiprocess cache sharing. Features optimized mset/mget, CBOR or JSON serialization (default CBOR), custom serializers, and automatic smart purging. It offers better resilience and performance compared to filesystem-based stores like node-cache-manager-fs-binary, benefiting from SQLite's ACID properties and faster local storage. The package has 100% test coverage and requires Node 14+.

npm install cache-manager-sqlite
INSTALL
IMPORT
SIG · CACHE-MANAGER-SQLI
C
cache-manager-sqlite
databasejavascriptv0.2.0
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 (store factory)
const sqliteStore = require('cache-manager-sqlite')
import sqliteStore from 'cache-manager-sqlite'
Package does not provide a named export; use CommonJS require. ESM import may fail if package lacks ESM wrapper.
cacheManager.caching with store
cacheManager.caching({ store: sqliteStore, options: { serializer: 'cbor', ttl: 20 } })
cacheManager.caching({ store: 'cache-manager-sqlite', options: {} })
The store must be the required factory function, not a string.
Multi-store with sqliteStore and redisStore
const multiCache = cacheManager.multiCaching([sqliteCache, redisCache])
const multiCache = cacheManager.multiCaching(sqliteCache, redisCache)
multiCaching expects an array of caches.

Demonstrates basic setup of cache-manager-sqlite with both in-memory and on-disk caches, including serialization options.

const sqliteStore = require('cache-manager-sqlite'); const cacheManager = require('cache-manager'); // Create an in-memory SQLite cache const cache = cacheManager.caching({ store: sqliteStore, options: { serializer: 'json', ttl: 20 } }); // Set and get a value await cache.set('key', { message: 'hello' }); const value = await cache.get('key'); console.log(value); // { message: 'hello' } // On-disk cache with custom table name const diskCache = cacheManager.caching({ store: sqliteStore, name: 'users', path: '/tmp/cache.db', options: { serializer: 'cbor', ttl: 60 } }); await diskCache.set('user1', { name: 'Alice' }); const user = await diskCache.get('user1'); console.log(user); // { name: 'Alice' }
Debug
Known issues
gotchaPackage uses CommonJS require; ESM import may not work as there is no ESM entry point.
fix
Use require('cache-manager-sqlite') or ensure your bundler/interpreter handles CJS modules.
affects: >=0.0.0
gotchaThe store must be passed as an object to cacheManager.caching, not as a string. Using a string like 'cache-manager-sqlite' will throw an error.
fix
Pass the required factory function directly: store: require('cache-manager-sqlite')
affects: >=0.0.0
gotchaThe 'name' option in cache config corresponds to the SQLite table name; if omitted, defaults to 'cache'. Ensure the table name does not conflict with existing tables.
fix
Explicitly set a unique 'name' per store to avoid collisions.
affects: >=0.0.0
gotchaWhen using multiCaching, the caches must be passed as an array. Passing separate arguments will cause an error.
fix
Use multiCaching([cache1, cache2]) instead of multiCaching(cache1, cache2).
affects: >=0.0.0
Errors
Common errors & fixes
Error: Cannot find module 'cache-manager-sqlite'
Package not installed or not installed in node_modules.
fix
Run 'npm install cache-manager-sqlite' and ensure it is listed in package.json.
TypeError: store must be an object
The store argument to cacheManager.caching is a string instead of the required factory function.
fix
Replace store: 'cache-manager-sqlite' with store: require('cache-manager-sqlite').
Error: SQLITE_ERROR: no such table: cache
The cache table does not exist yet. The store should auto-create tables, but it may fail if permissions or path issues occur.
fix
Ensure the write permissions for the directory and let the store create tables on first use. If using a custom 'name', ensure the table is created.
Upgrade
Version history
0.2.0latest on npm
Audit
Dependencies
cache-managerrequiredPeer dependency; this store is used with node-cache-manager's caching and multiCaching APIs.
sqlite3requiredRequired for SQLite database operations; async version used.
Agent activity
14 hits · last 30 days
node
12
OpenAI (training)
1
Resources
cache-manager-sqlite — npm install cache-manager-sqlite · libregistry