Category: Redis
Last updated May 20, 2026
Redis Caching Best Practices
Redis Caching Best Practices
Notes on keys naming conventions and eviction strategies when using Redis as a distributed cache.
1. Key Naming
Always use namespaces separated by colons:
app:domain:object:id
Example:
blog:posts:detail:getting-started
2. Setting TTL (Time To Live)
Never store cache entries without a TTL unless explicitly required. Always specify expiration times:
var options = new DistributedCacheEntryOptions()
.SetAbsoluteExpiration(TimeSpan.FromMinutes(60))
.SetSlidingExpiration(TimeSpan.FromMinutes(10));