System.Runtime.MemoryCache invalidation using Redis PubSub feature.
Install-Package RedisMemoryCacheInvalidation
quick start
First, you have to configure the library, mainly to setup a persistent redis connection and various stuff
// somewhere in your global.asax/startup.cs
InvalidationManager.Configure("localhost:6379", new InvalidationSettings());
Redis connection string follow StackExchange.Redis Configuration model
Threre are at least 3 ways to send invalidation messages :
- send an invalidation message via any redis client following the command
PUBLISH invalidate onemessagekey
- use
InvalidationManager.InvalidateAsync
(same as the previous one) - use keyspace notification (yes, RedisMemoryCacheInvalidation supports it)
Once an invalidation message is intercepted by the library, you can invalidate one or more items at the same time by using InvalidationSettings.InvalidationStrategy
InvalidationStrategyType.ChangeMonitor
=> a custom custom change monitorInvalidationManager.CreateChangeMonitor
InvalidationStrategyType.AutoCacheRemoval
=> use the automatic MemoryCache removal configured atInvalidationSettings.ConfigureAsync
InvalidationStrategyType.External
=> use the callback configured atInvalidationSettings.InvalidationCallback
Read more
- [Overview] (https://github.com/Cybermaxs/RedisMemoryCacheInvalidation/blob/master/docs/Overview.md)
- [Working with Redis] (https://github.com/Cybermaxs/RedisMemoryCacheInvalidation/blob/master/docs/Redis.md)
- [Configuration] (https://github.com/Cybermaxs/RedisMemoryCacheInvalidation/blob/master/docs/Configuration.md)
- [Examples] (https://github.com/Cybermaxs/RedisMemoryCacheInvalidation/blob/master/docs/Examples.md)
Read the introduction post for the initial version (beginning of 2014) here : https://techblog.betclicgroup.com/2013/12/31/implementing-local-memorycache-invalidation-with-redis/
Licensed under the terms of the MIT License
- Beginner => Download, Star, Comment/Tweet, Kudo, ...
- Amateur => Ask for help, send feature request, send bugs
- Pro => Pull request, promote
Thank you