Try our conversational search powered by Generative AI!

Anders Hattestad
Jun 7, 2010
  9550
(0 votes)

Performance and Scalability

Was at EPiServer Partner Summit, and had the pleasure to hear Magnus Stråle talked about this subject. The key feature I think he talked about was that you have to understand that html cache don’t always need to be correct. It’s like my mother always have told me: Its ok to cheat in poker, as long as you don’t get caught.

He talked about output Page cache, and different strategies to  cache it. 

In a scenario where you have a lot of logged in users, and or a lot of forms that are being submitted there will be very few actually hits in a page cache aproce, Since the unique key pr page will need to include the userID, and a post will not use the page cache..

In some sites I have made we have used an area cache technique.  This is an approce you can use if you have areas in your page that aint depended on the UserID, or areas that actully don’t bother if the Page is in a post back mode. It could even be parts that is always the same.

There is actully easy to make your own area cache. If you make a WebControl that overrides AddParsedSubObject like this

protected override void AddParsedSubObject(object obj)
{
    if (IsCached() && UseCache)
        return;
    base.AddParsedSubObject(obj);
}
and change the render method to something like this:
protected override void Render(System.Web.UI.HtmlTextWriter writer)
{
    if (IsCached()) 
        WriteCachedValue(writer);
    else if (UseCache)
        WriteAndUpdateCachedValues(writer);
    else
        base.Render(writer);     
}

Then you can retrive the content, and cache it

void WriteAndUpdateCachedValues(System.Web.UI.HtmlTextWriter writer)
{
    System.Web.UI.HtmlTextWriter  tmp = new System.Web.UI.HtmlTextWriter(new StringWriter());
    base.Render (tmp);
    cachedValue = tmp.InnerWriter.ToString();
    writer.Write(cachedValue);
    GetCacheKey.CachedValue=cachedValue;
    GetCacheKey.AddMiss();
}

Then the only thing that are needed is to have properties in the web control that sets the key you want to save your cache with. Some keys could be

public string CacheKey = "";
public bool CacheOnPageID = true;
public bool CacheOnUrlParameters = true;
public bool UseCache = true;
public bool CacheOnUserID=false;
public bool CacheOnUserRoles=true;
public bool CachePostback = false;

Then you could in your master page add this around sidebar, many, top and other elements, and set the cache properties based on your knowledge on what will change in the different parts of the page. You can then attach to the episerver datafactory events, and invalidate the different part of the cache when there is a page change.

You can’t add controls or stuff automaticly in other part of the cache area thou :)

The rest of the code is a bit more complex, so i want add it here.

Thanks for a great EPiServer Partner Summit and had a really nice time there. Was very fun to see the faces behind the blog posts :)

Jun 07, 2010

Comments

Please login to comment.
Latest blogs
Azure AI Language – Extractive Summarisation in Optimizely CMS

In this article, I demonstrate how extractive summarisation, provided by the Azure AI Language platform, can be leveraged to produce a set of summa...

Anil Patel | Apr 26, 2024 | Syndicated blog

Optimizely Unit Testing Using CmsContentScaffolding Package

Introduction Unit tests shouldn't be created just for business logic, but also for the content and rules defined for content creation (available...

MilosR | Apr 26, 2024

Solving the mystery of high memory usage

Sometimes, my work is easy, the problem could be resolved with one look (when I’m lucky enough to look at where it needs to be looked, just like th...

Quan Mai | Apr 22, 2024 | Syndicated blog

Search & Navigation reporting improvements

From version 16.1.0 there are some updates on the statistics pages: Add pagination to search phrase list Allows choosing a custom date range to get...

Phong | Apr 22, 2024