Skip to main content
Logo

Configure page caching

Contensis provides a number of ways to configure page caching to help you serve more pages and save server overhead.

Before we dive into how to set up page caching, a quick warning. Any page that has dynamic information on it shouldn't be cached. For example, if you have a message on your pages that say 'Hello <username>' and David looks at the page a copy is cached, the page will be added to the cache with 'Hello Dave.' However, when Jane comes to view the same page, the cached version will be shown instead so she will also see 'Hello Dave'. Now this is a very primitive example but the point still stands.

Use configuration settings

There are three configuration settings that can be made against any publishing server to control the way caching is carried out.

Contensis_Caching_StandardPageCacheDuration

This setting is the number of seconds a piece of content should remain cached before being invalidated. Each time a page is re-published it will invalidate the cache duration, so there isn't a lot of harm in setting this as high as you like.

Beware though that if a homepage has a news listing, the news listing will only be cached for perhaps 10 minutes before updating; as every Contensis webcontrol has its own caching settings.

Contensis_Caching_StandardListCacheDuration

This setting sets the duration that list controls should be cached for. This needs a separate config option simply because it is more likely that a listing will be updated more often than a full page.

Any controls that list dynamic data fall into this category, for example: News Archive, Blog List, What's New, Generic List etc. This will be applied to all pages that contains a list control, not the list control itself.

Contensis_Caching_EnableTrace

Sometimes you want to be able to find out which controls are either allowing or preventing caching. Setting this variable to true, will place a comment in the <head> of every page explaining how the caching engine is deciding to cache the page and if so, for how long and which controls are causing maximum durations.

Use the WebAPI

The WebAPI gives you a convenient way to manage caching settings at template level. This is useful if you have some sections of your site that don't change often or at all, and would like to set a longer cache duration than the rest of your site. Take a look at the gist below to see how to use this method.

Write your own cache

You can also write your own cache, although you must be sure to be careful when doing this as you could stop some Contensis webcontrols from caching properly. You can use any .NET code to write a cache with but see an example below for a reference: