Episerver 7 : How To Improve Site Performance With Caching For MVC

Adding in Output Caching Globally On All Controllers

First off, you can enable global ‘OutputCacheAttribute ‘ to cache all of your controllers.  This approach is a bit more flexible than having to add it to each action on your site, as recommended in several sources.  In order to add the cache globally. you need to add the following into your global.asax .

        protected void Application_Start()
{
AreaRegistration.RegisterAllAreas();
RegisterGlobalFilters(GlobalFilters.Filters);
}
public static void RegisterGlobalFilters(GlobalFilterCollection filters)
{
filters.Add(new OutputCacheAttribute 
{
Duration = 900,
VaryByParam = "*"
});
}

You may need some controllers to not use the caching, in this instance you can set the output cache to 0 by adding the following attribute on the individual actions:

[OutputCache(NoStore = true, Duration = 0, VaryByParam = "*")]

Notes

  • Several articles have inferred that you can just use id;epslanguagefor the VaryByParam. On testing I still had issues which is why I went for *.
  • If you set VaryByParam=”None” the menu in the editor will turn into a infinite loop.
  • If you delete the ‘outputCacheSettings’ the editor will not load.

Using a CUSTOM EPiServer 7 Cache Handler Using Donut Caching

I’m not taking any credit for this one but if you check out this page you can get a custom caching module for EPiServer 7 using MVC 4:

http://bergdaniel.se/asp-net-mvc-4-output-cache-with-episerver-7-preview

Caching VPP Folder contents

By default the cache expiration time is set to -1 day in EPiServer. This can be changed to a day adding in the following tag in your web.config configratuion section.

<location path=”Global”>
<staticFile expirationTime=”1.0:0:0″ />

Source : http://epiwiki.se/configuration/episerver-cms/caching-in-episerver-cms

Adding Kernal Caching
To add in extra static file caching you can add Kernal caching within the system.webserver tags.
<caching enabled=”true” enableKernelCache=”true”>
<profiles>
<add extension=”.js”
policy=”CacheForTimePeriod”
kernelCachePolicy=”CacheForTimePeriod”
duration=”00:02:00″
location=”Any” />
</profiles>
</caching>

Enabling Client Side Caching

To enable the cache headers for all static content in the folder (and sub folders) with a web.config:

<staticContent>
<clientCache cacheControlMode=”UseMaxAge” cacheControlMaxAge=”1.00:00:00″ />
</staticContent>
<httpProtocol>
<customHeaders>
<add name=”Cache-Control” value=”public” />
</customHeaders>
</httpProtocol>

References

Jon D Jones

Software Architect, Programmer and Technologist Jon Jones is founder and CEO of London-based tech firm Digital Prompt. He has been working in the field for nearly a decade, specializing in new technologies and technical solution research in the web business. A passionate blogger by heart , speaker & consultant from England.. always on the hunt for the next challenge

More Posts

0 replies

Leave a Reply

Want to join the discussion?
Feel free to contribute!

Leave a Reply

Your email address will not be published. Required fields are marked *