@courseproof/cache
v0.1.1
Published
[](https://opensource.org/licenses/MIT)
Downloads
347
Maintainers
Readme
@courseproof/cache
In-memory caching layer for certificate verification results. Uses LRU eviction with TTL support to avoid redundant network requests.
Exports
MemoryCacheBackend
In-memory Map-based implementation of the CacheBackend interface with automatic TTL eviction and configurable max entries.
| Method | Description |
|--------|-------------|
| get(key) | Retrieves a cached value (returns undefined if expired or missing) |
| set(key, value, ttlMs) | Stores a value with a TTL in milliseconds |
| delete(key) | Removes a key from cache |
| clear() | Empties the entire cache |
| has(key) | Checks if a key exists and is not expired |
| size | Returns the number of cached entries |
CertificateCache
Higher-level cache wrapping a CacheBackend with convenience methods for verification results.
| Method | Description |
|--------|-------------|
| getVerification(url) | Retrieves a cached CertificateResult |
| setVerification(url, value) | Caches a CertificateResult (default TTL: 1 hour) |
| hasVerification(url) | Checks if a URL has a cached result |
| invalidate(url) | Removes a cached verification |
| clear() | Empties the entire cache |
CacheOptions
| Option | Default | Description |
|--------|---------|-------------|
| defaultTtlMs | 3_600_000 (1 hour) | Default TTL for cached entries |
| maxEntries | 1000 | Maximum number of entries before LRU eviction |
| backend | MemoryCacheBackend | Custom CacheBackend implementation |
Usage
import { CertificateCache } from "@courseproof/cache";
const cache = new CertificateCache({ defaultTtlMs: 30 * 60 * 1000 }); // 30 min
// Store verification result
await cache.setVerification("https://coursera.org/verify/abc123", result);
// Retrieve cached result
const cached = await cache.getVerification("https://coursera.org/verify/abc123");
// Check without retrieving
const exists = await cache.hasVerification("https://coursera.org/verify/abc123");Installation
npm install @courseproof/cacheLicense
MIT — see LICENSE for details.
Part of the CourseProof monorepo.
