Anders Hattestad
Jun 7, 2010
  9587
(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
Opti ID overview

Opti ID allows you to log in once and switch between Optimizely products using Okta, Entra ID, or a local account. You can also manage all your use...

K Khan | Jul 26, 2024

Getting Started with Optimizely SaaS using Next.js Starter App - Extend a component - Part 3

This is the final part of our Optimizely SaaS CMS proof-of-concept (POC) blog series. In this post, we'll dive into extending a component within th...

Raghavendra Murthy | Jul 23, 2024 | Syndicated blog

Optimizely Graph – Faceting with Geta Categories

Overview As Optimizely Graph (and Content Cloud SaaS) makes its global debut, it is known that there are going to be some bugs and quirks. One of t...

Eric Markson | Jul 22, 2024 | Syndicated blog

Integration Bynder (DAM) with Optimizely

Bynder is a comprehensive digital asset management (DAM) platform that enables businesses to efficiently manage, store, organize, and share their...

Sanjay Kumar | Jul 22, 2024

Frontend Hosting for SaaS CMS Solutions

Introduction Now that CMS SaaS Core has gone into general availability, it is a good time to start discussing where to host the head. SaaS Core is...

Minesh Shah (Netcel) | Jul 20, 2024

Optimizely London Dev Meetup 11th July 2024

On 11th July 2024 in London Niteco and Netcel along with Optimizely ran the London Developer meetup. There was an great agenda of talks that we put...

Scott Reed | Jul 19, 2024