开发者

DataFactoryCache.CreateDependency in EPiServer returns CacheDependency with HasChanged==true

I'm using the following code to cache an object using the CacheManager class in EPiServer:

CacheManager.RuntimeCacheAdd(
                cacheKey, 
                myPageCollection,
                DataFactoryCache.CreateDependency(new PageReference(15)));
开发者_开发知识库

For some reason the CacheDependency object returned has HasChanged==true, even though the LastModified value doesn't change (and is indeed before DateTime.UtcNow).

In other words, my cached object will never stick since the dependency instantly clears the cache (because of HasChanged==true).

Any suggestions are greatly appreciated! :)


This isn't really a complete answer to "why", but here's what I can see:

When you create a CacheDependency for a specific page, that CacheDependency will have HasChanged==true until children for the page have been retrieved (and are thus cached).

So, in order to ensure my CacheDependency is properly initialized I have to go from this:

var cacheDependency = DataFactoryCache.CreateDependency(new PageReference(15)); // cacheDependency.HasChanged==true;             

to this:

var children = DataFactory.Instance.GetChildren(new PageReference(15));

var cacheDependency = DataFactoryCache.CreateDependency(new PageReference(15)); // cacheDependency.HasChanged==false;
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜