Skip to content
A layered caching implementation of IDistributedCache
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.


L1L2RedisCache is an implementation of IDistributedCache with a strong focus on performance. It leverages IMemoryCache as a level 1 cache and RedisCache as a level 2 cache, with level 1 evictions being managed via Redis Pub/Sub.

L1L2RedisCache is heavily inspired by development insights provided over the past several years by StackOverflow. It attempts to simplify those concepts into a performant IDistributedCache that can be more generally applied.


L1L2RedisCache can be registered during startup with the following IServiceCollection extension method:

services.AddL1L2DistributedRedisCache(options =>
    options.Configuration = "localhost";
    options.InstanceName = "Namespace";

The IOptions used is RedisCacheOptions, as there is a direct dependency on Microsoft.Extensions.Caching.Redis.

It is intended that L1L12RedisCache then be simply used via IDistributedCache dependency injection.


L1L2RedisCache will generally outperform RedisCache when used with very high volume or very large cache entries. This can be attribtued to the non-reliance on deferring to Redis continually, reducing time spent because of latency, network traffic, and, very minimally, Redis operations.


Due to the complex nature of distributed L1, cache entries with sliding expirations are specifically stored only in L2.

You can’t perform that action at this time.