Assembly: System.Runtime.Caching (in System.Runtime.Caching.dll)
Cache implementers use this method to wire themselves up to a change monitor. If you associate one or more change monitors with the cache item, you pass a CacheItemPolicy instance with a populated change monitors property to the cache item. A cache implementer that supports change monitors is responsible for iterating over the ChangeMonitors property and register the OnChangedCallback delegates with each change monitor that it finds.
Because the OnChangedCallback delegate includes an optional state parameter, a concrete change monitor implementation can pass optional state information. The cache implementer determines whether an explicit dependency on the type of state that a custom change monitor passes as part of the callback can be taken.
The base cache extensibility API has no requirement for explicit dependency on the type of state.
The implementation of the method automatically determines whether the state of the monitor has already changed at the time method is called. If the HasChanged property is true, then the method automatically calls the OnChangedCallback event handler, that was registered, through the OnChanged method. This occurs because it is possible that from the time a cache implementation creates a change monitor, to the time a cache implementation gets the monitor and wires itself up to it, the underlying monitored state has changed. If the state has already changed then the object that is passed to the OnChanged method is Nothing.
The method can be invoked only one time, and will throw an exception on subsequent calls.Notes to Implementers
You must call the method to be notified of any dependency changes. If a dependency change has already occurred, the OnChangedCallback instance will be called when is called. Otherwise, the OnChangedCallback instance will be called one time, either when the OnChanged method is called or when the Dispose method is called, whichever occurs first. The OnChangedCallback instance provided by the cache implementation should remove the cache entry and if it is requested by the cache caller, raise the necessary change or update event back to the original cache caller.
The object cache implementation must remove the cache entry that is associated with a dependency change.