@resolid/cache package provides a fully-typed, flexible cache system for modern TypeScript projects. It supports single and batch operations, optional TTL, and pluggable storage backends.
Installation
Basic Usage
Create a cache instance and perform basic operations:Core Operations
get() - Retrieve Value
Retrieve a value from the cache:packages/cache/src/index.ts:20):
set() - Store Value
Store a value in the cache with optional TTL:packages/cache/src/index.ts:26):
del() - Delete Value
Delete a value from the cache:packages/cache/src/index.ts:30):
clear() - Clear All Values
Remove all values from the cache:packages/cache/src/index.ts:34):
has() - Check Existence
Check if a key exists in the cache:packages/cache/src/index.ts:73):
Batch Operations
Perform operations on multiple keys efficiently:getMultiple() - Get Multiple Values
packages/cache/src/index.ts:38):
setMultiple() - Set Multiple Values
packages/cache/src/index.ts:47):
delMultiple() - Delete Multiple Values
packages/cache/src/index.ts:65):
Storage Backends
NullCache (Default)
A no-op cache that doesn’t store anything. Useful for development or disabling cache:MemoryCache
An in-memory cache using LRU eviction:packages/cache/src/stores/memory-cache.ts:7):
Custom Store
Implement your own cache store by implementing theCacheStore interface:
Configuration
Cache Options
Configure the cache with options:packages/cache/src/index.ts:6):
CacheStore Interface
TheCacheStore interface defines the contract for storage backends:
packages/cache/src/stores/types.ts:1
Common Patterns
Cache-Aside Pattern
Load data from cache, falling back to source:Write-Through Pattern
Update cache and source together:Cache Invalidation
Invalidate related cache entries:Memoization
Cache expensive function results:Batch Loading
Load multiple items efficiently:Namespaced Keys
Organize cache keys by namespace:TTL Strategies
Implement different TTL strategies:Resource Cleanup
Dispose of cache resources when done:packages/cache/src/index.ts:79):
API Reference
Cacher Class
See source atpackages/cache/src/index.ts:11