我们正在使用 MS Velocity,并将很快转向 AppFabric。我们有兴趣将来可能使用标签从缓存中检索项目。 Velocity/App Fabric API 包含一个添加方法,如下所示
public DataCacheItemVersion Add(string key,
object value,
IEnumerable<DataCacheTag> tags);
但是,没有任何方法可用于使用不需要指定区域的标记从缓存中检索对象。
问题在于,如果您使用 Add() 而不指定区域,您将不知道缓存管理器将对象放入哪个区域;因此,您在检索对象时无法指定区域。我在这里错过了一些非常简单的东西吗?
最佳答案
如果您使用 DataCache 类,则有多个可用的重载,包括第一个仅指定键的重载:
- DataCache.Get (String) - Gets an object from the cache using the specified key.
- DataCache.Get (String, out DataCacheItemVersion) - Gets an object from the cache using the specified key. You may also provide the version to obtain the specific version of a key, if that version is still the most current in the cache.
- DataCache.Get (String, String) - Gets an object from the specified region by using the specified key.
- DataCache.Get (String, out DataCacheItemVersion, String) - Gets an object from the specified region by using the specified key. You may also provide the version to obtain the specific version of a key, if that version is still the most current in the region.
来自 http://msdn.microsoft.com/en-us/library/microsoft.data.caching.datacache.get.aspx
关于c# - 如何在不知道区域的情况下通过标签从缓存中获取项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5316564/