Registry / storage / nsql-cache-datastore

nsql-cache-datastore

JSON →
library1.1.6jsnpmunverified

Google Datastore adapter for nsql-cache, enabling automatic caching of Datastore entities and queries. Version 1.1.6 integrates with nsql-cache (peer dependency ^1.1.4) to provide a managed LRU memory cache with configurable TTLs (default: 10 min for key fetches, 5 sec for queries). Key differentiators: transparent cache wrapping of the @google-cloud/datastore client, intelligent batch key fetching (only fetches missing keys from Datastore), and automatic cache invalidation on save/update/delete. Suitable for Node.js >=6.0, no TypeScript typings shipped. Released sporadically, last update 2018. Note: This adapter is also integrated into gstore-node.

npm install nsql-cache-datastore
INSTALL
IMPORT
SIG · NSQL-CACHE-DATASTO
N
nsql-cache-datastore
storagejavascriptv1.1.6
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.

DatastoreAdapter
✓ const DatastoreAdapter = require('nsql-cache-datastore');
✗ import DatastoreAdapter from 'nsql-cache-datastore';
Package does not ship ESM or types; use CommonJS require. The default export is a function that takes a Datastore instance.
default
✓ const DatastoreAdapter = require('nsql-cache-datastore');
Function is exported as module.exports = DatastoreAdapter. No named exports available.
nsql-cache (NsqlCache)
✓ const NsqlCache = require('nsql-cache');
✗ import { NsqlCache } from 'nsql-cache';
nsql-cache also uses CommonJS; the class is the default export.

Initializes a Datastore client with environment-based credentials, wraps it with nsql-cache-datastore adapter, creates an NsqlCache instance, and fetches a User entity (automatically cached).

const Datastore = require('@google-cloud/datastore'); const NsqlCache = require('nsql-cache'); const DatastoreAdapter = require('nsql-cache-datastore'); const datastore = new Datastore({ projectId: process.env.GCLOUD_PROJECT ?? '', keyFilename: process.env.GOOGLE_APPLICATION_CREDENTIALS ?? '', }); const db = DatastoreAdapter(datastore); const cache = new NsqlCache({ db }); async function getUser(id) { const key = datastore.key(['User', id]); return datastore.get(key); } getUser(1).then(console.log).catch(console.error);
Debug
Known issues
gotchaThe adapter only wraps @google-cloud/datastore methods: get, save, update, insert, upsert, delete. Other Datastore methods (e.g., runQuery, createQuery) are not cached.
fix
Use datastore.get() for key-based lookups to leverage caching. For queries, consider manual caching or use nsql-cache's query methods.
affects: >=1.0.0
deprecatedThe @google-cloud/datastore package has been deprecated in favor of @google-cloud/datastore v2+. Check compatibility with newer Datastore client versions.
fix
Test with latest @google-cloud/datastore; if issues arise, pin to an older version or migrate to gstore-node which includes the adapter.
affects: >=1.0.0
gotchaCache TTLs are global defaults; individual request-level overrides require passing options to the Datastore methods (e.g., datastore.get(key, { ttl: 60000 })).
fix
Refer to nsql-cache documentation for per-request TTL and cache bypass options.
affects: >=1.0.0
breakingVersion 1.0.0 changed the export from a constructor to a factory function. Older code using 'new DatastoreAdapter()' will break.
fix
Use DatastoreAdapter(datastore) instead of new DatastoreAdapter(datastore).
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: DatastoreAdapter is not a constructor
Using new DatastoreAdapter() but version >=1.0.0 exports a factory function.
fix
const db = DatastoreAdapter(datastore);
Cannot find module 'nsql-cache'
nsql-cache is a peer dependency and must be installed separately.
fix
npm install nsql-cache
Error: Datastore: 3 NOT_FOUND: No project ID could be determined
Missing Google Cloud credentials or project ID.
fix
Set GOOGLE_APPLICATION_CREDENTIALS environment variable or provide projectId in Datastore constructor.
Upgrade
Version history
1.1.6latest on npm
Audit
Dependencies
nsql-cacherequiredPeer dependency – provides the caching logic that this adapter plugs into.
Agent activity
16 hits · last 30 days
node
14
Amazon
1
Resources
nsql-cache-datastore — npm install nsql-cache-datastore · libregistry