Support for change monitors
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:
- FileMonitor (when a files changes)
- SignalMonitor (when the application triggers a "signal")
- Any other custom monitor implementation that is specific to the application
The way this would be used is as follows:
- Create a
CacheItem. - Add zero or more monitors to the cache item. For example, a
SignalMonitor. - 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.
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...