Registry / database / nsql-cache

nsql-cache

JSON →
library1.1.5jsnpmunverified

An advanced cache layer for NoSQL databases (v1.1.5, last updated ~2020). Vendor-agnostic with adapters for Google Datastore and potentially others. Uses node-cache-manager for multiple store support (e.g., LRU memory, Redis). Provides automatic read-through caching, write-through invalidation, and optional client wrapping for transparent cache management. Distinguishes itself by supporting auto-invalidation based on entity Kind when used with Redis sets. Requires Node >=6.0. Low maintenance cadence; last release was 2019. Not compatible with modern module systems (CJS only).

npm install nsql-cache
INSTALL
IMPORT
SIG · NSQL-CACHE
N
nsql-cache
databasejavascriptv1.1.5
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.

NsqlCache
const NsqlCache = require('nsql-cache');
import NsqlCache from 'nsql-cache'; // ESM not supported; use require
Package uses CommonJS only; no default export for ES modules.
nsql-cache-datastore
const dsAdapter = require('nsql-cache-datastore');
import dsAdapter from 'nsql-cache-datastore'; // ESM not supported
Adapter is also CJS-only; returns a function that wraps the datastore client.
cache (instance methods)
cache.get(key); cache.set(key, val, ttl); cache.del(key);
cache.get(key).then(...) // Does not return a Promise; callback-based in older versions
Methods like get/set/del are synchronous for memory store, but async for Redis. Check adapter docs.

Setup Google Datastore with nsql-cache, save and retrieve an entity, and run a query. Demonstrates auto-caching with default TTLs.

const Datastore = require('@google-cloud/datastore'); const NsqlCache = require('nsql-cache'); const dsAdapter = require('nsql-cache-datastore'); const datastore = new Datastore({ projectId: 'my-project', keyFilename: '/path/to/key.json' }); const db = dsAdapter(datastore); const cache = new NsqlCache({ db }); // Save an entity (auto-cached) const key = datastore.key(['Task', 'sample']); const task = { description: 'Buy milk', done: false }; datastore.save({ key, data: task }).then(() => { console.log('Entity saved and cached.'); // Retrieve it return datastore.get(key); }).then(([entity]) => { console.log('Retrieved from cache on second call:', entity); }); // Query with cache (5s default TTL) datastore.createQuery('Task').filter('done', '=', false).run().then(results => { console.log('Queried and cached'); });
Debug
Known issues
deprecatedPackage has not been updated since 2019; may have security vulnerabilities in dependencies.
fix
Consider migrating to alternative caching libraries like ioredis or datastore-cache.
affects: >=1.0.0
gotchaDefault cache TTL for queries is 5 seconds, which is very short for production use. May cause unexpected cache misses.
fix
Configure ttl.queries to a higher value (e.g., 600 seconds) in the NsqlCache constructor config.
affects: >=1.0.0
gotchaWhen wrapClient is false, you must manually invalidate cache on writes; otherwise stale data persists.
fix
Set wrapClient: true (default) or manually call cache.del() after save/delete operations.
affects: >=1.0.0
breakingNode version requirement says >=6.0, but newer Node LTS (12+) may have compatibility issues with transitive dependencies.
fix
Test on your Node version; consider using --openssl-legacy-provider if needed.
affects: >=1.0.0
Errors
Common errors & fixes
Error: Cannot find module 'nsql-cache-datastore'
Missing required adapter package.
fix
Run: npm install nsql-cache-datastore
TypeError: cache.get is not a function
Improper initialization of NsqlCache instance, or using ESM import.
fix
Ensure you use `const NsqlCache = require('nsql-cache');` and create instance with `new NsqlCache({db})`.
UnhandledPromiseRejectionWarning: Error: Invalid TTL value
Passed a non-positive number or string to TTL configuration.
fix
Ensure TTL values are positive integers (seconds). Example: `ttl: { keys: 600, queries: 300 }`
Upgrade
Version history
1.1.5latest on npm
Audit
Dependencies
nsql-cache-datastoreoptionalPrimary database adapter for Google Datastore; required for datastore usage
node-cache-managerrequiredCore dependency for multi-store caching logic; automatically installed
@google-cloud/datastoreoptionalGoogle Datastore client, required if using the datastore adapter
Agent activity
5 hits · last 30 days
node
4
Resources
nsql-cache — npm install nsql-cache · libregistry