API Overview
This section provides comprehensive documentation for all Celli APIs.
Core APIs
Cache Creation
- createCache() - Create a cache instance with options
- sync() - Create a basic synchronous cache
- See Source Caches for creating external data sources
Memoization
cache()- Memoize a function with options@Cache- Decorator for memoizing methodsmemo()- Simple memoization without configurationonce()- Ensure a function runs only once
Cache Management
- See Cache Manager for managing multiple cache instances
clean()- Global cleanup function
Composable Strategies
Build custom caches by composing strategies (see Composable Caches):
async()- Add async concurrencylru()- Add LRU evictionttl()- Add TTL expirationlifeCycle()- Add per-item lifecycleeffects()- Add constant effectsremote()- Add remote backupcompose()- Compose multiple strategies
Types and Interfaces
ICache- Basic cache interfaceAsyncCache- Async cache interfaceAnyCacheType- Union of all cache typesCacheKey<C>- Extract key type from cacheCacheValue<C>- Extract value type from cacheCleanable- Object with cleanup method
Constants
SourceCleanupPolicies- Cleanup policy enum
Quick Reference
Import Paths
// Main exports
import {
// Cache creation
createCache,
sync,
source,
// Memoization
cache,
Cache,
memo,
once,
// Management
createCacheManager,
clean,
// Composable strategies
async,
lru,
ttl,
lifeCycle,
effects,
remote,
compose,
// Types
ICache,
AsyncCache,
AnyCacheType,
CacheKey,
CacheValue,
// Constants
SourceCleanupPolicies
} from 'celli'
Common Patterns
Simple Memoization
import {cache} from 'celli'
const fn = cache((id: string) => expensiveOperation(id), {
cacheBy: (id) => id,
ttl: 5000,
lru: 100
})
Class Method Decorator
import {Cache} from 'celli'
class Service {
@Cache({
cacheBy: (id) => id,
async: true,
ttl: 5000
})
async getData(id: string) {
return await fetch(`/api/${id}`)
}
}
Custom Cache
import {compose, sync, async, lru, ttl} from 'celli'
const cache = compose(
async(),
lru({maxSize: 100}),
ttl({timeout: 5000})
)(sync())
With Remote Source
import {createCache, source} from 'celli'
const cache = createCache({
lru: 100,
source: source({
get: async (key) => await redis.get(key)
})
})
Next Steps
Browse the detailed documentation: