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.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.vscode
.gitignore
CacheMessage.cs
L1L2RedisCache.cs
L1L2RedisCache.csproj
LICENSE
README.md
ServiceCollectionExtensions.cs
azure-pipelines.yml

README.md

L1L2RedisCache

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.

Use

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.

Performance

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.

Caveats

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.