问题
In Windows Azure Caching (http://msdn.microsoft.com/en-us/library/windowsazure/hh914161.aspx), Microsoft.ApplicationServer.Caching.DataCacheException is thrown (with ErrorCode: KeyDoesNotExist), when someone tries to get a not-cached object (i.e., the key of the object does not exist).
Instead of handling DataCacheException, is there any way to check if the key exists gracefully?
thanks,
回答1:
The DataCache.Get(key) method returns null if the provided key is not found.
Any other methods that require the key to be present such as those concerned with locking will result in a DataCacheException.
来源:https://stackoverflow.com/questions/14551129/windows-azure-caching-best-practice-for-checking-whether-a-key-exist-or-not