{"id":19892142,"url":"https://github.com/maxpert/node-cache-manager-sqlite","last_synced_at":"2025-05-02T18:31:38.327Z","repository":{"id":45752712,"uuid":"512644312","full_name":"maxpert/node-cache-manager-sqlite","owner":"maxpert","description":"A modern SQLite store for node-cache-manager","archived":false,"fork":false,"pushed_at":"2022-09-28T05:05:34.000Z","size":205,"stargazers_count":55,"open_issues_count":3,"forks_count":3,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-04-21T21:21:28.999Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/maxpert.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-07-11T06:40:54.000Z","updated_at":"2025-02-14T06:41:25.000Z","dependencies_parsed_at":"2022-08-12T12:10:31.808Z","dependency_job_id":null,"html_url":"https://github.com/maxpert/node-cache-manager-sqlite","commit_stats":null,"previous_names":[],"tags_count":13,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/maxpert%2Fnode-cache-manager-sqlite","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/maxpert%2Fnode-cache-manager-sqlite/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/maxpert%2Fnode-cache-manager-sqlite/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/maxpert%2Fnode-cache-manager-sqlite/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/maxpert","download_url":"https://codeload.github.com/maxpert/node-cache-manager-sqlite/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252088520,"owners_count":21692810,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-12T18:21:43.215Z","updated_at":"2025-05-02T18:31:35.888Z","avatar_url":"https://github.com/maxpert.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# SQLite store for node cache manager\n\nA modern SQlite cache store for [node-cache-manager](https://github.com/BryanDonovan/node-cache-manager). Featuring:\n\n - Async SQLite3 using [sqlite3](https://github.com/TryGhost/node-sqlite3)\n - `async`/`await` support with Promise\n - 100% test coverage and production ready\n - Optimized `mset`/`mget` support\n - Supports CBOR for efficient and fast storage (selectable between `json` or `cbor` default: `cbor`)\n - Support for custom serializers\n - Smart purging support, no configuration required\n\n## Why?\n\nThe goal was to have a local key value storage built on top of [proven technology](https://www.sqlite.org/testing.html).\nWhile other options like [node-cache-manager-fs-binary](https://github.com/sheershoff/node-cache-manager-fs-binary) have \nsimilar functionality; they are littered with all sort of problems from race conditions, (multi-process) to corruption.\nSQLite on the other end has been battle tested, and using WAL allows multiple node processes (forked web servers) to share the same\ncache across various processes, without the headaches of flat file based systems.\n\nSQLite based storage is ideal for:\n - Faster local storage than filesystem. [Yes you heard it right](https://www.sqlite.org/fasterthanfs.html)\n - Reslience to corruption and recovery.\n - Multiprocess Node.js processes (typical in server deployments with many cores)\n - Large number of entries.\n\n## Installation\n\n```\nnpm i cache-manager-sqlite\n```\n\n## Requirements\n\n - SQLite 3 with [sqlite3 package](https://github.com/TryGhost/node-sqlite3)\n - Node 14+\n\n## Usage\n\n## Single store\n```js\nconst sqliteStore = require('cache-manager-sqlite')\nconst cacheManager = require('cache-manager')\n\n// SQLite :memory: cache store\nconst memStoreCache = cacheManager.caching({\n    store: sqliteStore,\n    options: {\n        serializer: 'json', // default is 'cbor'\n        ttl: 20 // TTL in seconds\n    }\n})\n\n// On disk cache on employees table\nconst cache = cacheManager.caching({\n    store: sqliteStore,\n    name: 'employees',\n    path: '/tmp/cache.db'\n})\n\n\n// TTL in seconds\nawait cache.set('foo', {test: 'bar'}, {ttl: 10})\nconst value = await cache.get('foo')\n```\n\n### Multi-store example:\n\n```js\nconst cacheManager = require('cache-manager')\nconst redisStore = require('cache-manager-ioredis')\nconst sqliteStore = require('cache-manager-sqlite')\n\nconst redisCache = cacheManager.caching({ store: redisStore, db: 0, ttl: 600 })\nconst sqliteCache = cacheManager.caching({ store: sqliteStore, path: '/tmp/cache.db', name: 'users', options: { ttl: 600 } })\n\nconst multiCache = cacheManager.multiCaching([sqliteCache, redisCache])\n\n// Basic get/set\nawait multiCache.set('foo2', 'bar2', { ttl: customTTL })\nconst v = await multiCache.get('foo2')\n\n// Wrap call example\nconst userId = 'user-1'\n\n// Optionally pass ttl\nawait multiCache.wrap(userId, { ttl: customTTL }, async () =\u003e {\n    console.log(\"Calling expensive service\")\n    await getUserFromExpensiveService(userId)\n})\n\n// set and get multiple\nawait multiCache.mset('foo1', 'bar1', 'foo0', 'bar0') //Uses default TTL\nawait multiCache.mset('foo1', 'bar1', 'foo3', 'bar3', {ttl: customTTL})\nawait multiCache.mget('foo1', 'foo3')\n```\n\n## License\n\nThe `node-cache-manager-sqlite` is licensed under the MIT license.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmaxpert%2Fnode-cache-manager-sqlite","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmaxpert%2Fnode-cache-manager-sqlite","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmaxpert%2Fnode-cache-manager-sqlite/lists"}