MichaCo / CacheManager

CacheManager is an open source caching abstraction layer for .NET written in C#. It supports various cache providers and implements many advanced features.
http://cachemanager.michaco.net
Apache License 2.0
2.33k stars 458 forks source link

CacheManager with With SystemRuntimeCache and Redis backplane does not receive events from the Redis cache. #296

Open siraj-ur-rahman opened 4 years ago

siraj-ur-rahman commented 4 years ago

I am using CacheManager for 2 layers of caching to increase speed across my applications. I'm using InMemory cache along with Redis as a back plane.

I'm working with invalidating the local in-memory cache data. I have subscribed to the item update and remove event on redis cache but my application does not receive any events. When I run the command it shows that it has already subscribed to the channel which can be seen from the result of the command given below.

localhost:6379> pubsub channels *
1) "__Booksleeve_MasterChanged"
2) "CacheManagerBackplane"

The event registration code can be seen below:

ICacheManager<object> manager = GetCacheInstance();
            manager.OnRemoveByHandle += EventHandlerRemove;
 public void EventHandlerRemove(object sender, CacheItemRemovedEventArgs e){}

This is cache registration.

var manager = CacheFactory.Build<object>(settings => {
                settings.WithJsonSerializer();
                settings
                    .WithSystemRuntimeCacheHandle()
                    .And
                    .WithRedisConfiguration("redis", config => {
                        config.WithAllowAdmin()
                            .WithDatabase(0)
                            .WithEndpoint("localhost", 6379);
                    })
                    .WithRedisBackplane("redis")
                    .WithRedisCacheHandle("redis", true);
                settings.WithUpdateMode(CacheUpdateMode.None);
            });

Is there anything wrong with this code or do I require some additional configuration for this to make it work?

what I want to achieve:

I have Redis cache and multiple services are using this for invalidating their data using the events of this Redis cache. Each service have its own local in-memory cache related to the data in the main Redis cache. when the data is modified in the Redis cache each local cache will receive an event of data updated or removed from Redis cache and hence they will remove their local copy too to avoid serving stale data.