CacheEngine
API Reference for the CacheEngine class
CacheEngine
High-performance cache with automatic garbage collection and dependency tracking.
Import
Constructor
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
staleTime | number | 300000 (5 min) | Default stale time |
gcTime | number | 1800000 (30 min) | Garbage collection time |
maxSize | number | 100000 | Maximum cache entries |
When the cache reaches maxSize, the least-valuable entry is evicted before a
new one is inserted. Entries are ranked by a weighted score that favours entries
accessed recently and frequently (each access is worth roughly one second of
recency) plus a bonus for active observers; the lowest-scoring entry is evicted
first. Entries with observers or in-flight fetches are never evicted; if every
entry is protected, temporary overflow is permitted until entries become
available.
Methods
get<T>(queryKey)
Get cache entry by key.
getByHash<T>(keyHash)
Get cache entry by hash.
set<T>(options)
Create or update cache entry.
delete(queryKey)
Delete cache entry.
invalidate(queryKey)
Invalidate entry and dependencies.
invalidateAll(predicate?)
Bulk invalidate entries.
clear()
Clear all entries.
collectGarbage()
Remove expired entries.
has(queryKey)
Check if entry exists.
entries()
Get all cache entries.
getStats()
Get cache statistics.
Properties
| Property | Type | Description |
|---|---|---|
size | number | Number of entries |