Output Caching
In the next three posts or so I will be covering the types of caching available in ASP.Net 2.0 and MOSS. The first of these three types is output caching. Output caching is the ability to render a page once and then store the HTML output of that page in cache for a set period of time. Each user (and I use this term fairly loosely for caching; I will explain in a little bit) that hits the page after it is cached will receive the cached page. The output cache caches a page based on type of user, either authenticated or anonymous, and by the type of browser. Yes, out caching stores each page for each browser type, so the Mozilla rendering of a page will be separate than the IE rendering.
This type of output saves both on processor speed and the number of round trips to the database which can be pretty slow depending on your MOSS configuration.
Thus type of caching is only available if you have the MOSS Publishing Infrastructure feature enabled. If your site is built on the Publishing Portal or Collaboration Portal then you have this by default.
Go to Site Actions - Site Settings - All Site Settings and go to Cache Profiles to set up the profile and its settings. You can have profiles for different types of users, one for anonymous, or one for authenticated users.
You need to give the profile a title and you can give it a display name and description. You can then check the checkbox for Performa ACL check. This will check for security trimming when caching. If you do not need security trimming then uncheck the box to increase performance.
You then need to check the box labeled Enabled to enable the caching on that profile. This check box allows you to easily trouble shoot a profile by enabling and disabling in one click.
You then set the duration to hold the cached pages before re-rendering the page. This number is in seconds. A good rule of thumb is to start at about 2 hours and check the performance of your server and adjust the cache duration accordingly.
The Check for Changes box if checked will check to see if the page has been changed. If it has it will re-render the page and store it in the cache. If the page has not changed then the cache will be used. If you check this box it will decrease performance as the site now has to check each page for changes before it renders the page.
You can then choose to vary the cache profile based on custom parameters, HTTP headers, query string parameters, or User rights. For most people you can leave the defaults that come with the base profiles.
Cacheability defines where the page gets cached and is one of the following: none - the page is not cached, server - the page is cached on the server, private - the page is cached in the browser, server and private - the page is cached at both the server and the browser.
The last two check boxes allow for caching for authenticated users and for contributors.
After you have created the profile you then need to enable the caching and select which profile to use for both anonymous users and authenticated users. There are also some check boxes on this page to allow sub-sites and page layouts to override the caching of the rest of the site. This can come in handy if there are a couple of pages that render code differently depending on a selection. You may need to turn caching off on that page layout for the page to render correctly.
You can also enable debugging information in the pages. This is handy to test whether pages are staying in the cache and to make sure they are staying in there for the entire duration time. This will place a timestamp on the very last line of the HTML source that will give you the profile that rendered the cached page and what time and date the page was cached.
Caching requires a lot of fine tuning for performance of your server or server farm. Dedicate the time, though, and your site will run smoothly and scale easily.
Here is a wonderful article on performance tuning and caching that will aid you on your journey:
http://blogs.msdn.com/ecm/archive/2006/11/08/how-to-make-your-moss-2007-web-site-faster-with-caching.aspx
In the next post I will explain object caching and how to track it.
Labels: cache profiles, MOSS, output cache, Sharepoint 2007
2 Comments:
This was a very helpful post! However, I have some concerns about the "check for changes box". In your post, you say that it will check if the page has been changed and then re-render it and store it in the cache. However, when I tried this out, it seems like the entire cache is invalidated, including all subsites and pages. If I edit a page on the site, pages on the subsites get invalidated and reloaded as well. Is this the expected behaviour?
As far as I know this is not expected behavior. Are you editing the page layout or a master page or simply the ASPX page. If you are editing a page layout or master page, this would cause all of the cache to be invalidated and all pages would be re-built and cached. If this is not the case there may be a bug in the caching mechanism. I have not run into this issue on the SharePoint sites I have worked on. Keep me posted if you find anything.
Post a Comment
Subscribe to Post Comments [Atom]
<< Home