2.0.0 • Published 7 months ago

excache v2.0.0

Weekly downloads
-
License
ISC
Repository
github
Last release
7 months ago

Extensible Cache

Key features

  • ⚡️ TTL and LRU cache
  • 💾 File System and Memory backends out of box
  • 🔌 Simple interface, extensible to other backends
  • 📦 ESM (ECMAScript Module)
  • 🔬 100% TypeScript

Usage

Simple in-memory cache:

import { Cache, MemoryCache } from 'excache';

// Keep Cache<T> interface, so you can swap cache implementation
const cache: Cache<T> = new MemoryCache<T>({
    maxSize: 100,   // Specify to enable LRU cache
    ttl: 60 * 1000, // Specify to enable TTL cache
});

await cache.get('foo'); // T | undefined
await cache.set('foo', myValue);

Upgrade to FS cache:

import { Cache, FsCache } from 'excache';

const cache: Cache<T> = new FsCache({
    dir: '/path/to/cache',
    toString(value: string): T {
        // Serialize to text data
    },
    fromString(value: stirng): T {
        // Deserialize from text data
    },
    maxSize: 100,
    ttl: 60 * 1000,
});

await cache.get('foo');
await cache.set('foo', myValue);
2.0.0

7 months ago

1.1.0

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago