November Happy Hour will be moved to Thursday December 5th.

How to properly set Content Provider Cache Timeout ?

Vote:
 

I have tried to set a cache timeout in Content Provider,

I have used the below methods,

Method 1: Set the cache setting before adding the content to cache

var content= getContent(something);
SetCacheSettings(content, new CacheSettings(TimeSpan.FromMinutes(1)));

AddContentToCache(content);

Method 2: Set the cache settings after adding the content to cache

var content= getContent(something);

AddContentToCache(content);
SetCacheSettings(content, new CacheSettings(TimeSpan.FromMinutes(1)));

Above methods have no impact. It stays in the cache. If this is not the proper way, is there a way to set the cache timeout?

Or is it possible delete the content provider cache on demand?

#201715
Feb 28, 2019 8:40
Vote:
 

Solved. I have used ClearProviderPagesFromCache()

#201716
Feb 28, 2019 9:00
Vote:
 

Hi!

You need to override that SetCacheSettings method instead of calling it yourself. In AddContentToCache, default cache settings are created, and then SetCacheSettings is called so you can modify default settings if needed. Something like this:

protected override void SetCacheSettings(IContent content, CacheSettings cacheSettings)
{
    // For sliding expiration
    cacheSettings.SlidingExpiration = TimeSpan.FromMinutes(1);
    cacheSettings.AbsoluteExpiration = System.Web.Caching.Cache.NoAbsoluteExpiration;

    // For absolute expiration
    cacheSettings.SlidingExpiration = System.Web.Caching.Cache.NoSlidingExpiration;
    cacheSettings.AbsoluteExpiration = DateTime.UtcNow.AddMinutes(1);
}
#201720
Feb 28, 2019 10:27
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.