我想在ASP.NET CacheObject中有一个项,如果它被更改,许多依赖项将被删除
所以。。在请求中
-
如果出现提示并且它存在于缓存中,则删除根对象,所有依赖关系也将被删除
-
-
将其他依赖于根对象的对象添加到缓存中
当我这样做的时候,我得到了一个错误“
An attempt was made to reference a CacheDependency object from more than one Cache entry
"
有人找到办法了吗?
这里有一些代码,它不是我实际存储的,但它代表相同的任务
public class HomeController : Controller
{
private const string ROOT_KEY = "ROOT";
protected override void Initialize(System.Web.Routing.RequestContext requestContext)
{
base.Initialize(requestContext);
if(Request.QueryString["clearcache"]!=null){
// removed the root, hopefully removing all dependents
HttpContext.Cache.Remove(ROOT_KEY);
}
if (HttpContext.Cache[ROOT_KEY] == null)
{
// create the root entry
HttpContext.Cache[ROOT_KEY] = string.Empty;
}
if(HttpContext.Cache[Request.Url.AbsolutePath]==null){
// add the url if not already added
HttpContext.Cache.Insert(
Request.Url.AbsolutePath, string.Empty,
new CacheDependency(null, new []{ROOT_KEY}));
}
}
}