Cache module for SecureStack with support for Redis, Memory, and Memcached
npm install @lemur-bookstores/secure-stack-cacheioredis.
memjs.
better-sqlite3.
mongodb.
bash
npm install @lemur-bookstores/secure-stack-cache
`
Usage
$3
`typescript
import { CacheManager } from '@lemur-bookstores/secure-stack-cache';
const cache = new CacheManager({
store: 'memory',
memory: {
max: 500, // Max items
ttl: 60, // Default TTL in seconds
},
});
await cache.set('key', 'value');
const value = await cache.get('key');
`
$3
`typescript
import { CacheManager } from '@lemur-bookstores/secure-stack-cache';
const cache = new CacheManager({
store: 'redis',
redis: {
host: 'localhost',
port: 6379,
ttl: 3600, // Default TTL
},
});
`
$3
`typescript
import { CacheManager } from '@lemur-bookstores/secure-stack-cache';
const cache = new CacheManager({
store: 'memcached',
memcached: {
servers: 'localhost:11211',
options: {
expires: 60,
},
},
});
`
$3
`typescript
import { CacheManager } from '@lemur-bookstores/secure-stack-cache';
const cache = new CacheManager({
store: 'sqlite',
sqlite: {
path: './cache.sqlite', // Defaults to :memory:
table: 'my_cache', // Defaults to 'cache'
ttl: 60,
},
});
`
$3
`typescript
import { CacheManager } from '@lemur-bookstores/secure-stack-cache';
const cache = new CacheManager({
store: 'mongo',
mongo: {
url: 'mongodb://localhost:27017',
dbName: 'my_app',
collectionName: 'cache_items',
ttl: 60,
},
});
`
API
$3
- get
- set
- del(key: string): Promise
- clear(): Promise
- has(key: string): Promise
- getProvider(): CacheProvider`