Registry / storage / cache-sqlite-lru-ttl

cache-sqlite-lru-ttl

JSON →
library1.2.2jsnpmunverified

A persistent cache library combining SQLite storage with LRU eviction and TTL expiration for Node.js and browsers (via SQL.js). The current stable version is 1.2.2, with irregular releases. Key differentiators: dual LRU+TTL eviction policy, ACID-backed persistence via SQLite, and support for both synchronous and asynchronous APIs. Unlike in-memory caches (e.g., lru-cache), data survives restarts; unlike pure SQLite caches, bounded memory is guaranteed via LRU. ESM-only, TypeScript types built-in.

npm install cache-sqlite-lru-ttl
INSTALL
IMPORT
SIG · CACHE-SQLITE-LRU-T
C
cache-sqlite-lru-ttl
storagejavascriptv1.2.2
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.

Cache
import { Cache } from 'cache-sqlite-lru-ttl'
const { Cache } = require('cache-sqlite-lru-ttl')
ESM-only package. CommonJS require() will fail with ERR_REQUIRE_ESM.
CacheOptions
import type { CacheOptions } from 'cache-sqlite-lru-ttl'
import { CacheOptions } from 'cache-sqlite-lru-ttl'
CacheOptions is a TypeScript type, not a runtime value. Use type import for proper tree-shaking.
default (Cache class)
import Cache from 'cache-sqlite-lru-ttl'
import { default as Cache } from 'cache-sqlite-lru-ttl'
Cache is the default export. Named import { Cache } also works (they are the same), but default import is idiomatic.

Create a persistent LRU+TTL cache backed by SQLite, set and get a value, then clean up.

import Cache from 'cache-sqlite-lru-ttl'; async function main() { const cache = new Cache({ maxSize: 1000, ttl: 60000, path: './my-cache.db' }); await cache.init(); await cache.set('key1', { data: 'hello' }); const entry = await cache.get('key1'); console.log(entry); // { data: 'hello' } await cache.close(); } main().catch(console.error);
Debug
Known issues
breakingConstructor options changed: `maxEntries` replaced by `maxSize` in v1.2.0.
fix
Replace `maxEntries` with `maxSize` (same meaning).
affects: <1.2.0
gotchaCache must be initialized via `cache.init()` before any get/set operations.
fix
Always await `cache.init()` after construction.
affects: >=1.0.0
deprecated`cache.destroy()` deprecated in favor of `cache.close()` since v1.2.0.
fix
Use `cache.close()` instead of `cache.destroy()`.
affects: >=1.0.0 <1.2.0
gotchaTTL is in milliseconds, not seconds. Setting ttl: 60 evicts in 60ms, not 60s.
fix
Use milliseconds: e.g., ttl: 60000 for 1 minute.
affects: >=1.0.0
breakingBrowser usage requires SQL.js WebAssembly file to be served alongside.
fix
Ensure `sql-wasm.wasm` is accessible or configure via `sqlWasmPath` option.
affects: >=1.0.0
Errors
Common errors & fixes
Error [ERR_REQUIRE_ESM]: Must use import to load ES Module: /node_modules/cache-sqlite-lru-ttl/build/index.js
Using require() with an ESM-only package.
fix
Change to `import Cache from 'cache-sqlite-lru-ttl'` and ensure project 'type': 'module' or use .mjs extension.
TypeError: cache.get is not a function
Trying to use cache before calling init().
fix
Add `await cache.init()` after creating the cache instance.
SQLITE_NOTADB: Database handle is not a database
Corrupt database file or invalid path in browser environment without proper WASM setup.
fix
On browser, ensure sql-wasm.wasm is served; on Node, delete the db file and recreate.
Error: TTL must be a positive number or 0 for no TTL
Passed a negative TTL or non-numeric value.
fix
Provide ttl as a non-negative integer (milliseconds), e.g., ttl: 60000.
Upgrade
Version history
1.2.2latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
20 hits · last 30 days
node
17
OpenAI (training)
2
Resources
cache-sqlite-lru-ttl — npm install cache-sqlite-lru-ttl · libregistry