Does NCache Open-Source 4.4SP1 support item-level notifications?

93 views Asked by At

I am trying to use NCache as a shared key-value store with data-change notifications. Here is what I tried:

var cache = NCache.InitializeCache("mycache");
cache.RegisterCacheNotification("123", CacheDataModified, EventType.ItemAdded | EventType.ItemUpdated);

var data = 7;
var cacheItem = new CacheItem(data) {
    Priority = CacheItemPriority.NotRemovable
};

cache.Insert("123", cacheItem);

while(true) {
    Thread.Sleep(200);
}

And the callback:

private static void CacheDataModified(string key, CacheEventArg cacheeventargs) {
    var newValue = cacheeventargs.Item;
    ;
}

I set a breakpoint in the callback, but the only notification I get is a notification with key = "123", and cacheeventargs.CacheItemRemovedReason = Underused.

That makes me wonder whether NCache Open-Source 4.4SP1 supports item-level notifications. Am I doing something wrong?

1

There are 1 answers

3
Laurent LA RIZZA On BEST ANSWER

This is actually normal. Item-level notification seems to work this way. The callback receives a notification that item "123" has been updated, and a subsequent Get must be issued to get the new value.

The CacheItemRemovedReason has said value because it is the enum's default value.