public class CancellationChangeToken : IChangeToken
{
// 1. It holds a private reference to your token
private readonly CancellationToken _token;
public CancellationChangeToken(CancellationToken token)
{
_token = token;
}
// 2. The wrapper's "HasChanged" property just checks your token
public bool HasChanged => _token.IsCancellationRequested;
// 3. It tells the Cache how to listen for the "Cancel" event
public IDisposable RegisterChangeCallback(Action<object> callback, object state)
{
// It simply hooks into the standard CancellationToken.Register method
return _token.Register(callback, state);
}
// Most change tokens aren't active by default, but this one is
public bool ActiveChangeCallbacks => true;
}