여러 캐시 된 항목을위한 calchedacatile
-
15-09-2020 - |
문제
ASP.NET CacheObject에 항목을 갖고 싶습니다.
그래서 .. 요청
- 메시지가 표시되고 캐시에있는 경우 루트 객체를 제거하면 모든 종속성이 너무 제거됩니다
- 캐시에서 루트 오브젝트를 확인하십시오. 존재하지 않으면 를 추가하십시오.
- 루트 오브젝트에 종속성이있는 캐시에 다른 오브젝트를 추가
이렇게하면 "An attempt was made to reference a CacheDependency object from more than one Cache entry
"오류가 발생합니다
캐시 된 항목에 많은 종속성을 적용하기 위해 aggregateCacheDependency를 수행 할 수 있지만 다른 방향으로 수행 할 수없는 것 같습니다.
아무도이 일을 할 수있는 방법을 찾았습니까?
여기에 몇 가지 코드가 있지만 실제로 저장하고있는 것은 아니지만 동일한 작업을 나타냅니다
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}));
}
}
}
.해결책
위의 코드는 작동합니다. 키는 매번 새로운 cachedependence를 생성했습니다. 비 - 의사 코드에서 동일한 객체를 재사용하려고 시도했지만, 이는 오류가 설명되었다.
@adeel & jaroslav replies에 감사드립니다
다른 팁
단일 이벤트에 대한 여러 무효화 문제는 현재 사용 가능한 캐시가 기본적으로 또는 효율적으로 처리하지 않는 것입니다. Tagcache 의 저자로서, 나는 그것을 시도하고 그것을 시도하고 그것을 보게한다.시나리오에서 더 나은 선택 일 수 있습니다.
제휴하지 않습니다 StackOverflow