{"id":45617,"library":"nsql-cache","title":"nsql-cache","description":"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).","status":"maintenance","version":"1.1.5","language":"javascript","source_language":"en","source_url":"https://github.com/sebelga/nsql-cache","tags":["javascript","cache","google datastore","gcloud node","google app engine","nodejs"],"install":[{"cmd":"npm install nsql-cache","lang":"bash","label":"npm"},{"cmd":"yarn add nsql-cache","lang":"bash","label":"yarn"},{"cmd":"pnpm add nsql-cache","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Primary database adapter for Google Datastore; required for datastore usage","package":"nsql-cache-datastore","optional":true},{"reason":"Core dependency for multi-store caching logic; automatically installed","package":"node-cache-manager","optional":false},{"reason":"Google Datastore client, required if using the datastore adapter","package":"@google-cloud/datastore","optional":true}],"imports":[{"note":"Package uses CommonJS only; no default export for ES modules.","wrong":"import NsqlCache from 'nsql-cache'; // ESM not supported; use require","symbol":"NsqlCache","correct":"const NsqlCache = require('nsql-cache');"},{"note":"Adapter is also CJS-only; returns a function that wraps the datastore client.","wrong":"import dsAdapter from 'nsql-cache-datastore'; // ESM not supported","symbol":"nsql-cache-datastore","correct":"const dsAdapter = require('nsql-cache-datastore');"},{"note":"Methods like get/set/del are synchronous for memory store, but async for Redis. Check adapter docs.","wrong":"cache.get(key).then(...) // Does not return a Promise; callback-based in older versions","symbol":"cache (instance methods)","correct":"cache.get(key); cache.set(key, val, ttl); cache.del(key);"}],"quickstart":{"code":"const Datastore = require('@google-cloud/datastore');\nconst NsqlCache = require('nsql-cache');\nconst dsAdapter = require('nsql-cache-datastore');\n\nconst datastore = new Datastore({ projectId: 'my-project', keyFilename: '/path/to/key.json' });\nconst db = dsAdapter(datastore);\nconst cache = new NsqlCache({ db });\n\n// Save an entity (auto-cached)\nconst key = datastore.key(['Task', 'sample']);\nconst task = { description: 'Buy milk', done: false };\ndatastore.save({ key, data: task }).then(() => {\n  console.log('Entity saved and cached.');\n  // Retrieve it\n  return datastore.get(key);\n}).then(([entity]) => {\n  console.log('Retrieved from cache on second call:', entity);\n});\n\n// Query with cache (5s default TTL)\ndatastore.createQuery('Task').filter('done', '=', false).run().then(results => {\n  console.log('Queried and cached');\n});","lang":"javascript","description":"Setup Google Datastore with nsql-cache, save and retrieve an entity, and run a query. Demonstrates auto-caching with default TTLs."},"warnings":[{"fix":"Consider migrating to alternative caching libraries like ioredis or datastore-cache.","message":"Package has not been updated since 2019; may have security vulnerabilities in dependencies.","severity":"deprecated","affected_versions":">=1.0.0"},{"fix":"Configure ttl.queries to a higher value (e.g., 600 seconds) in the NsqlCache constructor config.","message":"Default cache TTL for queries is 5 seconds, which is very short for production use. May cause unexpected cache misses.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Set wrapClient: true (default) or manually call cache.del() after save/delete operations.","message":"When wrapClient is false, you must manually invalidate cache on writes; otherwise stale data persists.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Test on your Node version; consider using --openssl-legacy-provider if needed.","message":"Node version requirement says >=6.0, but newer Node LTS (12+) may have compatibility issues with transitive dependencies.","severity":"breaking","affected_versions":">=1.0.0"}],"env_vars":null,"search_vec":"'2019':82 '2020':14 '6.0':75 'adapt':19 'advanc':5 'agnost':17 'app':98 'auto':62 'auto-invalid':61 'automat':40 'base':64 'cach':3,6,29,44,55,92 'cadenc':78 'cjs':89 'client':51 'compat':84 'databas':10 'datastor':22,94 'distinguish':57 'e.g':35 'engin':99 'entiti':66 'gcloud':95 'googl':21,93,97 'invalid':48,63 'javascript':91 'kind':67 'last':12,79 'layer':7 'low':76 'lru':36 'mainten':77 'manag':30,56 'memori':37 'modern':86 'modul':87 'multipl':32 'node':28,74,96 'node-cache-manag':27 'nodej':100 'nosql':9 'nsql':2 'nsql-cach':1 'option':50 'other':25 'potenti':24 'provid':39 'read':42 'read-through':41 'redi':38,71 'releas':80 'requir':73 'set':72 'store':33 'support':34,60 'system':88 'transpar':54 'updat':13 'use':26,69 'v1.1.5':11 'vendor':16 'vendor-agnost':15 'wrap':52 'write':46 'write-through':45","created_at":"2026-06-07T12:55:53.319565+00:00","updated_at":"2026-06-07T12:55:53.319565+00:00","problems":[{"fix":"Run: npm install nsql-cache-datastore","cause":"Missing required adapter package.","error":"Error: Cannot find module 'nsql-cache-datastore'"},{"fix":"Ensure you use `const NsqlCache = require('nsql-cache');` and create instance with `new NsqlCache({db})`.","cause":"Improper initialization of NsqlCache instance, or using ESM import.","error":"TypeError: cache.get is not a function"},{"fix":"Ensure TTL values are positive integers (seconds). Example: `ttl: { keys: 600, queries: 300 }`","cause":"Passed a non-positive number or string to TTL configuration.","error":"UnhandledPromiseRejectionWarning: Error: Invalid TTL value"}],"ecosystem":"npm","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":null,"cli_version":null,"type":"library","homepage":"https://github.com/sebelga/nsql-cache#readme","github":"https://github.com/sebelga/nsql-cache","docs":null,"changelog":null,"pypi":null,"npm":"nsql-cache","openapi_spec":null,"status_page":null,"smithery":null,"categories":["database"],"base_url":null,"auth_type":null,"provenance":{"verified_status":null,"verified_at":null,"last_verified":"2026-06-07","next_check":"2026-09-05","install_tag":null}}