Eviction Policies
When the cache is full, an eviction policy decides what to drop. MountSQLI’s
MemoryCache supports three.
Policies
Section titled “Policies”| Policy | Evicts | Best when |
|---|---|---|
| LRU | least recently used | general purpose, recency matters |
| LFU | least frequently used | hot keys should survive |
| FIFO | first in, first out | simple, order-based churn |
Configure
Section titled “Configure”import { CacheManager, MemoryCache } from "@mountsqli/cache";
const manager = new CacheManager({ l1: new MemoryCache({ max: 1000, policy: "LRU" }),});How each works
Section titled “How each works”- LRU tracks last access time; drops the stalest.
- LFU counts accesses; drops the least popular.
- FIFO keeps an insertion queue; drops the oldest entry.
Best practices
Section titled “Best practices”- Start with LRU — it fits most read patterns.
- Use LFU for very skewed “hot key” workloads.
- Size
maxto your working set; too small = thrash, too big = memory bloat.
Common mistakes
Section titled “Common mistakes”- Setting
maxtoo low — every read misses. - Using FIFO when recency matters (drops still-useful entries).
Related
Section titled “Related”- Overview — L1/L2 layers.
- Tags & Invalidation — explicit invalidation.
