Virtual Happy Hour this month, Jun 28, we'll be getting a sneak preview at our soon to launch SaaS CMS!

Try our conversational search powered by Generative AI!

Expire cache on Custom Repository Items


We've created a custom content asset provider repository which pulls data from an external data source. We've then used identity mapper and mapped it so that it can be used by EPiServer CMS. 

Our problem is that once the content asset is cached, episerver doesn't request for the live call again since its cached. 

We need to know how to expire that cache as well as what the duration of the cache is.

Edited, Feb 15, 2021 9:55

How do you cache the content asset? If you use IObjectInstanceCache/ISynchronizedObjectInstanceCache (which is the recommended way), when you add an object to cache you can control how long before the cache will expire, using CacheEvictionPolicy 

if you want to remove the cache actively, just remove the cache key

Feb 15, 2021 11:43

So, we're not caching anything ourselves.

We just inherit from "ContentProvider" and then implement all the necessary operations. Unfortunately i'm not allowed to post hyperlinks, otherwise i would've posted a snippet.

public class MyContentProvider : ContentProvider


protected override IContent LoadContent(ContentReference contentLink, ILanguageSelector languageSelector){}

protected override IList<GetChildrenReferenceResult> LoadChildrenReferencesAndTypes(ContentReference contentLink, string languageID, out bool languageSpecific){}


This is what we do. Then ofcourse we hook it up to make this turn up in the Asset pane as a new tab.

The problem is that the results of "LoadChildrenReferencesAndTypes" is cached after the first call. And we're trying to figure out where it is cached and how we can expire it.

Feb 23, 2021 6:34

I am looking into the implementation of ContentProvider, and can't find where the cache is implemented (Admittedly I could have missed something). Are you sure it is cached at that level, but not on higher level (IContentRepository for example)

Feb 23, 2021 8:42

It could be at a higher level. We're not sure about that. 

Our content provider makes live API calls to an external data source. When we were debugging, we noticed that when we expand a node in the asset tree, live calls are going through, but the second time around, data turns up instantaneously, but its not making a live call. So we understand that its cached somewhere. We are trying to understand where exactly its cache (it must be SynchronizedObjectCache im guess) and how we can get the key if we need to expire it manually. 

Since our last update, we also found another function that we could override

protected override void SetCacheSettings(IContent content, CacheSettings cacheSettings){}

This allows us to set the cache interval, which is good, but we still have certain conditions where we would like to "manually" expire the cache.

Feb 24, 2021 9:48

Hi Quan, do you have any further insight that could be helpful?

Mar 01, 2021 5:26
Quan Mai - Mar 01, 2021 9:23
Unfortunately no, I haven't had time to dig more into this. As always, you can reach out to developer support service for help

Is that a paid/premium service? How would i go about doing that?

Mar 05, 2021 12:45

Just reach out to it should not cost money, at least at the beginning. 

Mar 05, 2021 15:53

Thanks Quan. I've proceeded to do so. 

Mar 08, 2021 7:41
* 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.