Don't miss out Virtual Happy Hour this Friday (April 26).

Try our conversational search powered by Generative AI!

Anders Hattestad
Jun 7, 2010
  9546
(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
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

Optimizely and the never-ending story of the missing globe!

I've worked with Optimizely CMS for 14 years, and there are two things I'm obsessed with: Link validation and the globe that keeps disappearing on...

Tomas Hensrud Gulla | Apr 18, 2024 | Syndicated blog

Visitor Groups Usage Report For Optimizely CMS 12

This add-on offers detailed information on how visitor groups are used and how effective they are within Optimizely CMS. Editors can monitor and...

Adnan Zameer | Apr 18, 2024 | Syndicated blog

Azure AI Language – Abstractive Summarisation in Optimizely CMS

In this article, I show how the abstraction summarisation feature provided by the Azure AI Language platform, can be used within Optimizely CMS to...

Anil Patel | Apr 18, 2024 | Syndicated blog

Fix your Search & Navigation (Find) indexing job, please

Once upon a time, a colleague asked me to look into a customer database with weird spikes in database log usage. (You might start to wonder why I a...

Quan Mai | Apr 17, 2024 | Syndicated blog