PageProvider - Clear cached object

Member since: 2003
 

I have a pageprovider where I want to clear a cached object when the
"ClearProviderPagesFromCache()" method is called. The cached object contains data from the source system.
The cached object is like the "XmlPages" in the XmlPageProvider.

Do I accomplish this by adding a CacheDependency when I cache my object or do I add my CacheKey in the SetCacheSettings methods?

I have read the article http://labs.episerver.com/en/Blogs/Johan-Bjornfot/Dates/2008/10/PageProvider---Control-the-page-cache/ but I'm not sure how to accomplish it.

Can anyone help me on the way?

Regards Hans

#26138 Nov 20, 2008 21:00
  • Member since: 2004
     

    ClearProviderPagesFromCache is never called directly from EPiServer. It is method that custom implementers can call to flush all pages from a specific PageProvider.

     If your custom object is dependent on a specific page then you would add a cache dependency to that page when the custom object is added to cache. Then you could have some code like:

    string pageCacheKey = DataFactoryCache.PageCommonCacheKey(pageLink);
    CacheManager.RuntimeCacheInsert("yourkey", yourObject, new CacheDependency  (null, new string[1]{pageCacheKey}));

    If you want your cached object to be removed when all pages from the page providers is removed (e.g. when whole Page cache is cleared e.g. by a change in a PageType etc or when somebody calls ClearProviderPagesFromCache) then you would add a dependency to the common key for the provider like:

    string commonProviderKey = "EPPageProvider:" + ProviderKey;
    CacheManager.RuntimeCacheInsert("yourkey", yourObject, new CacheDependency  (null, new string[1]{commonProviderKey}));

    Ps.

    Unfortunately is the property ProviderCacheKey on PageProviderBase private which is why you have to construct it yourself as in commonProviderKey above. I have added a bug that we should change it to public.

    Ds.

    #26177 Nov 24, 2008 12:52
  • This message was deleted by Johan Björnfot at Nov 24, 2008 12:57.
  • Member since: 2003
     

    Thanks Johan

    The second proposal was what I was looking for. In the end though I have solved with my own ClearCache() method where I clear my cached object and also call ClearProviderPagesFromCache().

    The problem I got when adding the CacheDependency was that my cached object was cleared everytime when pages where added to the ProviderCache.

    /Hans

    #26191 Nov 25, 2008 9:03
This thread is locked and should be used for reference only. Please use the Episerver CMS 7 and earlier versions forum to open new discussions.
Please login to post a reply