ASP.NET CacheObjectにアイテムを入れたいのですが、変更すると、いくつかの依存アイテムが削除されます。
だから..リクエストで
- プロンプトが表示され、それがキャッシュに存在する場合、ルートオブジェクトを削除すると、すべての依存関係も削除されます
- キャッシュ内のルートオブジェクトを確認します。存在しない場合は追加します
- ルートオブジェクトに依存する他のオブジェクトをキャッシュに追加します
これを行うと、エラーが発生します " An attempt was made to reference a CacheDependency object from more than one Cache entry
"
AggregateCacheDependencyを実行して、1つのキャッシュされたアイテムに多くの依存関係を適用できるようですが、その逆はできないようです。
誰かがこれを行う方法を見つけましたか?
ここにいくつかのコードがあります、それは私が実際に保存しているものではありませんが、それは同じタスクを表しています
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}));
}
}
}