Registry / database / bun-sqlite-cache

bun-sqlite-cache

JSON →
library1.2.0jsnpmunverified

A lightweight in-memory cache for Bun using SQLite, supporting LRU eviction and TTL. Version 1.2.0 provides a Bun-specific port of sqlite-lru-cache with synchronous Gzip compression. Designed for high-performance caching in serverless or CLI environments. Active maintenance, type-safe with TypeScript definitions.

npm install bun-sqlite-cache
INSTALL
IMPORT
SIG · BUN-SQLITE-CACHE
B
bun-sqlite-cache
databasejavascriptv1.2.0
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.

BunSQLiteCache
import { BunSQLiteCache } from 'bun-sqlite-cache'
const BunSQLiteCache = require('bun-sqlite-cache')
ESM import is required as the package is ESM-only.
BunSQLiteCacheConfiguration
import { BunSQLiteCacheConfiguration } from 'bun-sqlite-cache'
Type import for configuration options; use with TypeScript.
ValueWithMeta
import { ValueWithMeta } from 'bun-sqlite-cache'
Type import for get() with withMeta=true.

Demonstrates basic CRUD operations, TTL expiry, compression, and persistent storage configuration.

import { BunSQLiteCache } from 'bun-sqlite-cache'; const cache = new BunSQLiteCache(); cache.set('user:1', { name: 'Alice', email: 'alice@example.com' }); const user = cache.get('user:1'); console.log(user); // { name: 'Alice', email: 'alice@example.com' } // With TTL cache.set('temp', 'expires in 5 seconds', { ttlMs: 5000 }); setTimeout(() => { console.log(cache.get('temp')); // undefined after 5 seconds }, 6000); // With compression cache.set('large', 'data', { compress: true }); // With options const persistentCache = new BunSQLiteCache({ database: './cache.db', maxItems: 1000, defaultTtlMs: 60000 });
Debug
Known issues
gotchaBunSQLiteCache is Bun-specific and will not work in Node.js or Deno.
fix
Use only in Bun runtime.
affects: all
gotchaValues are serialized using v8's serialization API. Non-serializable objects (e.g., functions, symbols) will cause errors.
fix
Ensure stored values are JSON-serializable or compatible with v8 serialization.
affects: all
gotchaCompression uses Bun's synchronous gzip; blocking the event loop for large values may impact performance.
fix
Use compression only for values where the CPU cost is acceptable.
affects: all
deprecatedThe 'defaultTtlMs' option was previously misspelled as 'defaultTtlMs' in early documentation; now correctly 'defaultTtlMs'. No breaking change.
fix
Use options.defaultTtlMs (only one 't' in 'default').
affects: 1.0.x
deprecatedget(withMeta) might return undefined for non-existent keys; ensure proper type narrowing.
fix
Check for undefined before accessing value.meta.
affects: all
Errors
Common errors & fixes
SyntaxError: Cannot use import statement outside a module
Using require() on an ESM-only package.
fix
Use dynamic import: const { BunSQLiteCache } = await import('bun-sqlite-cache');
TypeError: Bun is not defined
Code executed in Node.js or Deno.
fix
Run with 'bun run' instead of 'node' or 'deno'.
Error: Data must be a string or a Buffer
Attempting to store non-serializable value (e.g., function).
fix
Ensure value is serializable, e.g., use JSON.stringify manually or avoid storing functions.
Upgrade
Version history
1.2.0latest on npm
Audit
Dependencies
bunrequiredUses Bun-specific APIs (Bun.gzipSync, Bun.sqlite)
Agent activity
13 hits · last 30 days
node
10
OpenAI (training)
1
Resources
bun-sqlite-cache — npm install bun-sqlite-cache · libregistry