Windows Azure缓存-检查密钥是否存在的最佳实践
在Windows Azure缓存中( http://msdn.microsoft.com/en-us/library/windowsazure/hh914161.aspx ),当有人尝试获取未缓存的对象(例如,该对象不存在).
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).
除了处理DataCacheException之外,还有什么方法可以检查密钥是否存在?
Instead of handling DataCacheException, is there any way to check if the key exists gracefully?
谢谢
DataCache.Get(key)方法将返回null.
The DataCache.Get(key) method returns null if the provided key is not found.
任何其他要求提供密钥的方法(例如与锁定有关的方法)都将导致DataCacheException.
Any other methods that require the key to be present such as those concerned with locking will result in a DataCacheException.