in Windows Azure Shared Cache:
suppose I do the following:
try
{
mCache.Remove(key);
Trace.WriteLine("removed successfully from Azure Shared Cache");
}
catch (DataCacheException e)
{
WorkerRole.log.Info(e.ToString());
}
is it right to say that if the code reached to the Trace.WriteLine
command, then the operation completed successfully? (otherwise, it would be throwing DataCacheException
.
I know I can register to the event CacheOperationCompleted
, but is my code can be a good alternative to test operation success? (for Put/Remove methods).
thanks
Remove
method returnsboolean
flag indicating whether an item identified by the givenkey
has been removed (true
) or not (false
).So if you want to check operation result I would suggest following approach:
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:
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.).