1

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?

Laurent LA RIZZA
  • 2,905
  • 1
  • 23
  • 41

1 Answers1

1

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.

Laurent LA RIZZA
  • 2,905
  • 1
  • 23
  • 41
  • See what's available and what's not from [NCache Edition comparison](http://www.alachisoft.com/ncache/edition-comparison.html) – Basit Anwer Feb 24 '16 at 09:42
  • @BasitAnwer: Actually, if you read the question well, I wondered about the support exactly because I read the Edition Comparison and it claimed support for this feature, which seemed not to be the case when I tried. – Laurent LA RIZZA Feb 24 '16 at 18:29
  • 1
    Well, yes you're right then. `CacheItemRemovedReason` only makes sense when the `cacheeventargs.EventType == ItemRemoved` – Basit Anwer Feb 25 '16 at 06:15