在过去的几天里,我一直在使用Azure缓存。良好做法是使用本地缓存功能来防止往返到分布式缓存。
可以在文档中阅读;当调用dataCache.Get(.)时,应用程序首先检查本地缓存中的版本是否可用,如果没有,则从分布式缓存中检索对象。问题是本地版本可能比对象的分布式版本更早。为了解决这个问题,方法‘dataCache.GetIfNewer(.)’可用于检查本地对象的版本是否与分布式版本不同,如果与分布式版本不同,则返回新对象。
到目前为止,good...now我的问题;我已经创建了两个独立的应用程序(应用程序A,en应用程序B)来测试Azure缓存机制。两个应用程序都在两个不同的(物理)位置上运行,因此它们都有自己的本地缓存,但它们都使用相同的分布式缓存。
在使本地缓存无效的过程中,是否确实发生了一些变化?我测试了以下场景并发现本地缓存是自动更新的:
使用密钥"CacheTest"
这有多奇怪啊?最近Azure缓存中有什么变化吗?是的.我确信我打开了本地缓存,是的,我已经将本地缓存的超时设置为3600秒(1小时)。
有人能确认Azure缓存已经改变了吗?
编辑尼克:那么你的意思是,我在荷兰微软网站上找到的下一行代码都是胡说八道?当本地缓存自动更新时,不需要调用'GetIfNewer‘方法:http://www.dotnetmag.nl/Artikel/1478/Windows-Azure-AppFabric-Caching
///
/// Ensures that the newest version of a cached object is returned
/// from either the local cache or the distrbuted cache.
///
public TCachedObjectType GetNewest<TCachedObjectType>(string key) :
where TCachedObjectType : class
{
DataCacheItemVersion version;
// Gets cached object from local cache if it exists.
// Otherwise gets cached object from distributed cache and
// adds it to local cache.
object cachedObject = cache.Get(key, out version);
// Gets cached object from distributed cached if it is newer
// than given version.
// If newer it adds it to local cache.
object possiblyNewerCachedObject =
cache.GetIfNewer(key, ref version);
if (possiblyNewerCachedObject != null)
{
// Cached object from distributed cache is newer
// than cached object from local cache.
cachedObject = possiblyNewerCachedObject;
}
return cachedObject as TCachedObjectType;
}
发布于 2012-01-21 14:24:16
如果描述的行为与appfabric速度相同,则所描述的行为与预期的行为相同。当启用本地缓存时,意味着当给定节点从分布式缓存请求缓存项时,它会询问分布式缓存当前版本是什么。如果本地缓存版本与分布式版本匹配,则从本地缓存返回数据。如果没有,则从分布式缓存中检索最新值,将其本地缓存并返回。这样做的想法是,如果任何节点更新密钥,那么即使appfabric已经在本地缓存了它们,所有节点也将始终被确保获得最新版本。分布式缓存跟踪最新版本及其数据存储位置。
https://stackoverflow.com/questions/8953530
复制相似问题