Blog
Mert Özen's blog posts on software development, backend, frontend, and DevOps.
Caching Strategy: What to Cache, at Which Layer and for How Long
A caching decision starts with measurement: in Bookstore the category menu, with 2 queries per request and a 19.9 ms p95, was the only real candidate, and HybridCache cut p95 to 3.2 ms and 4,000 queries to 0, while the cheap, per-user cart should not be cached. TTL is derived from freshness requirements, and each layer's invalidation owner is decided up front.
IMemoryCache in Depth: SizeLimit, Eviction, Change Tokens and the Hidden Stampede in GetOrCreate
In an IMemoryCache with a full SizeLimit, an entry that exceeds the limit is never cached: book 101 added to a 100-unit cache was rejected, and background compaction evicted Low priority entries first, then the least recently used, bringing the cache down to 85. GetOrCreateAsync isn't atomic; 100 concurrent requests on an empty cache ran the factory 100 times, while striped SemaphoreSlim locks and HybridCache cut that to 1. Expiration has no timer; group invalidation uses change tokens.