Anders Hattestad
Jun 7, 2010
(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)
and change the render method to something like this:
protected override void Render(System.Web.UI.HtmlTextWriter writer)
    if (IsCached()) 
    else if (UseCache)

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();

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


Please login to comment.
Latest blogs
Customizing Property Lists in Optimizely CMS

Generic property lists is a cool editorial feature that has gained a lot of popularity - in spite of still being unsupported (officially). But if y...

Allan Thraen | Oct 2, 2022 | Syndicated blog

Content Delivery API – The Case of the Duplicate API Refresh Token

Creating a custom refresh provider to resolve the issues with duplicate tokens in the DXC The post Content Delivery API – The Case of the Duplicate...

David Lewis | Sep 29, 2022 | Syndicated blog

New Optimizely certifications - register for beta testing before November 1st

In January 2023, Optimizely is making updates to the current versions of our certification exams to make sure that each exam covers the necessary...

Jamilia Buzurukova | Sep 28, 2022

Optimizely community meetup - Sept 29 (virtual + Melbourne)

Super excited to be presenting this Thursday the 29th of September at the Optimizely community meetup. For the full details and RSVP's see the...

Ynze | Sep 27, 2022 | Syndicated blog