Remove
method returns boolean
flag indicating whether an item identified by the given key
has been removed (true
) or not (false
).
So if you want to check operation result I would suggest following approach:
if(mCache.Remove(key))
{
Trace.WriteLine("removed successfully from Azure Shared Cache");
}
As far as Put
method is concerned, this might be a bit more complicated.
Basically, if your cache.Put(key, value)
method completes successfully (no exceptions), you can assume your item has been added to your cache.
However, Azure cache items can be evicted from the cache (that depends on the cache size and item expiration time - default item expiration time is 48 hours for shared caching)
So in order to avoid any "surprises" I would recommend cache usage pattern as follows:
- Get item from cache by a key
- If cache return Null then create that item and put it into the cache
- Perform operation on the item
Also as a side note, I would recommend using in-role caching instead of shared caching service (mostly because it is cheaper, has more features etc.).