
[英]To get the details of tag associated with object when the object is evicted in Appfabric cache
[英]Why is cache object stored in session when using AppFabric?
我今天第一次去了AppFabric - 缓存(又名Velocity女士)并检查了msdn虚拟实验室。
https://cmg.vlabcenter.com/default.aspx?moduleid=4d352091-dd7d-4f6c-815c-db2eafe608c7
我有这个代码示例,我没有。 它创建一个缓存对象并将其存储在会话状态中。 文档只是说:
我们需要将缓存对象存储在Session状态,并在每次需要使用它时检索该对象的相同实例。
这不是我以前在ASP.NET中使用缓存的方式。 这种模式的原因是什么,我必须使用它吗?
private DataCache GetCache()
{
DataCache dCache;
if (Session["dCache"] != null)
{
dCache = (DataCache)Session["dCache"];
if (dCache == null)
throw new InvalidOperationException("Unable to get or create distributed cache");
}
else
{
var factory = new DataCacheFactory();
dCache = factory.GetCache("default");
Session["dCache"] = dCache;
}
return dCache;
}
这是因为DataCacheFactory
是一个昂贵的对象 - 您不希望每次要访问缓存时都创建它的实例。
他们在实验室中向您展示的是如何创建DataCacheFactory
实例一次以获取DataCache
实例,然后将该DataCache实例存储在Session状态,以便每次访问缓存时都可以返回到该实例。
当然,这仍然意味着你要为每个用户创建一个DataCacheFactory实例,我认为将它存储在Application状态将是一个更好的设计。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.