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

ICacheManager OnXyz event wires getting crossed #310

Closed erizzo closed 3 years ago

erizzo commented 4 years ago

I have 2 ICacheManager instances, ICacheManager<Foo> and ICacheManager<Bar>. One is a typical in-memory handle+Redis handle+backplane setup, the other is in-memory handle only with Redis backplane. For the <Foo> cache manager only, I register with the OnXyz events (OnAdd, OnPut, OnRemove, etc) to just write some log messages when those events happen, including the eventArgs.key.

What's strange is that I'm getting events for both cache manager instances, both <Foo> and <Bar>. In the debugger, I see an event with the Bar keys and the sender arg is actually the ICacheManager<Foo> instance!

I've set a breakpoint at the point where I add my event listeners (fooCacheManager.OnAdd += ...) to confirm that it is only being called once, so I'm confused why my little monitor is getting all events for the other instance.

erizzo commented 4 years ago

Also interesting (to me at least) is that the events always have an Origin of Remote even though my current testing only involves my single process connected to Redis running locally - all Puts, Adds, Updates, and Removes are running in a single process.

MichaCo commented 3 years ago

Sorry for the late answer,

Regarding why the second cache receives events, isn't that what you want if you use the backplane with in-memory cache? Even without an actual redis backend, the backplane will try to invalide things if possible. So, whenever the Foo instance changes something, the Bar instance will get notified via the backplane.

If you don't want that, you can configure different backplane channel names.