Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/sjdonado/cache-manager-bun-sqlite3
Fast and compact sqlite3 cache store for Bun
https://github.com/sjdonado/cache-manager-bun-sqlite3
bun-sqlite cache-manager
Last synced: about 4 hours ago
JSON representation
Fast and compact sqlite3 cache store for Bun
- Host: GitHub
- URL: https://github.com/sjdonado/cache-manager-bun-sqlite3
- Owner: sjdonado
- Created: 2024-07-21T17:48:30.000Z (4 months ago)
- Default Branch: master
- Last Pushed: 2024-07-23T06:22:55.000Z (4 months ago)
- Last Synced: 2024-11-01T21:46:00.566Z (5 days ago)
- Topics: bun-sqlite, cache-manager
- Language: TypeScript
- Homepage: https://www.npmjs.com/package/cache-manager-bun-sqlite3
- Size: 166 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Bun SQLite Store for [node-cache-manager](https://github.com/BryanDonovan/node-cache-manager)
- Runs on top of [bun-sqlite](https://bun.sh/docs/api/sqlite)
- Optimized `mset`/`mget` support
- Multiple encoders support: `msgpackr`, `cbor`, `json`
- Auto purge (clean expired records every hour)## Installation
```
bun add cache-manager-bun-sqlite3
```## Usage
### Single store
```ts
import cacheManager from 'cache-manager';
import bunSqliteStore from 'cache-manager-bun-sqlite3';// SQLite :memory: cache store
cache = await cacheManager.caching(bunSqliteStore, {
serializer: 'json', // default is 'msgpackr'
ttl: 20, // TTL in seconds
});// On-disk cache on employees table
const cache = await cacheManager.caching(bunSqliteStore, {
name: 'employees',
path: '/tmp/cache.db',
});// TTL in seconds
await cache.set('foo', { test: 'bar' }, 30);
const value = await cache.get('foo');// TTL in seconds
await cache.set('foo', { test: 'bar' }, 30);
const value = await cache.get('foo');
```### Multi-store example:
```ts
import cacheManager from 'cache-manager';
import bunSqliteStore from 'cache-manager-bun-sqlite3';
import redisStore from 'cache-manager-ioredis';const redisCache = await cacheManager.caching({ store: redisStore, db: 0, ttl: 600 });
const sqliteCache = await cacheManager.caching({
store: sqliteStore,
path: '/tmp/cache.db',
name: 'users',
ttl: 600,
});const multiCache = cacheManager.multiCaching([sqliteCache, redisCache]);
// Basic get/set
await multiCache.set('foo2', 'bar2', customTTL);
const v = await multiCache.get('foo2');// Wrap call example
const userId = 'user-1';// Optionally pass ttl
await multiCache.wrap(userId, customTTL, async () => {
console.log('Calling expensive service');
await getUserFromExpensiveService(userId);
});// set and get multiple
await multiCache.mset('foo1', 'bar1', 'foo0', 'bar0'); //Uses default TTL
await multiCache.mset('foo1', 'bar1', 'foo3', 'bar3', customTTL);
await multiCache.mget('foo1', 'foo3');
```Fork from [node-cache-manager-sqlite](https://github.com/maxpert/node-cache-manager-sqlite)