To configure RedisMemoryCacheInvalidation
, you should use one of the InvalidationManager.ConfigureAsync
methods.
Three parameters are available to configure it :
- redisConfig:string : Redis connection string. Check StackExchange.Redis Configuration model for more details. A basic example is
localhost:6379
. - mux:ConnectionMultiplexer : an existing StackExchange.Redis.ConnectionMultiplexer that you want to reuse.
- settings:InvalidationSettings : see below for more details.
InvalidationSettings is the main configuration object
- InvalidationStrategy:InvalidationStrategyType : How to handle invalidation notifications : notify ChangeMonitor, execute callback or automatically remove an item from the cache.
- TargetCache:MemoryCache : the target MemoryCache instance when
InvalidationStrategy
is set toAutoCacheRemoval
. - EnableKeySpaceNotifications:bool : allow subscribe to keyevents notification
__keyevent*__:
. - InvalidationCallback:Action : an callback that is invoked when
InvalidationStrategy
is set toExternal
.
Thanks to StackExchange.Redis a persistent connection is established between your application and the redis server. That's why it's important to configure it very early at startup : Global.asax, Owin Startup, ... In this way, you won't lose notification messages.