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.34k stars 457 forks source link

Support for change monitors #203

Open sfmskywalker opened 6 years ago

sfmskywalker commented 6 years ago

The API currently has support for providing an expiration date (plus various modes). What would be nice however is to also have a way to provide change monitors (a la ObjectCache / MemoryCache) / or "volatile tokens" (as implemented in Orchard) that allow an application to trigger the change monitor / volatile token. Examples of monitors/tokens would be:

The way this would be used is as follows:

  1. Create a CacheItem.
  2. Add zero or more monitors to the cache item. For example, a SignalMonitor.
  3. When some application-specific condition arrises, signalMonitor.Trigger() is called, which causes the cache to evict or expire the associated cache item.

This I think would be a very powerful addition, making cache eviction a breeze. Currently, one has to keep references to cache keys in order to evict them; with the monitors, that is no longer necessary.

MichaCo commented 6 years ago

I didn't answer earlier because this is something which has been asked several times as it is related to cache dependency management. Which is a feature CM doesn't provide. Added it to the backlog. But for starters, adding change monitors to distributed cached keys will not work very well or will be very complex to implement...