Optimize output cache
When Sitefinity pages are loaded for the first time, they go through the following main stages:
This is the compiling of the page and all the widgets on the page. The widget properties are queried from the database and the widgets are compiled with the properties.
When a page is updated in the backend, it will force the page to be recompiled on its next request.
- Output generation
This is the output generated from the requested page URL. This is the static HTML of the page and its output is cached. This provides the ability to serve the page immediately when it is in the output cache, because the HTML is already generated - the page and the widgets are already compiled and served directly.
Using the output cache, you can perform the following optimizations:
- Ensure output cache is turned on for all pages.
For more information, see Administration: Cache for pages and libraries.
- Increase the duration of the output cache.
You can extend it up to 24 hours (86400 seconds). You can configure this setting per output cache profile.
For more information, see Administration: Configure cache profiles.
- Disable the output cache variation by user agent.
Disable the caching per browser and browser versions and serve the output cache of the page on the first request to all browsers.
To do this, navigate to Administration » Settings » Advanced » System » Output Cache Settings » Output Cache Profiles. Select the profile and deselect Vary by user agent checkbox.
- Consider the output cache variation by all parameters.
By default, cache output varies by all parameters - query strings and posted parameters.
In some scenarios, this setting may not be optimal.
To configure it, navigate to Administration » Settings » Advanced » System » Output Cache Settings » Output Cache Profiles. Select the profile and in Vary by custom, enter the following, depending on your scenario:
- cache.VaryByParams["*"] = true; cache.VaryByParams.IgnoreParams = false;
- cache.VaryByParams.IgnoreParams = true;
- Decide whether you want the output cache to depend on permissions.
Output cache can be invalidated on permission change.
To configure this, navigate to Administration » Settings » Advanced » Pages and select or deselect Disable Output cache invalidation when permission is changed.
Minimize the usage of Secured (protected) widgets
Such widgets have view permissions different than the default ones, that is, Everyone. Pages with such widgets are not output cached for logged in users - both backend and frontend. The output caching is leveraged only for anonymous users.
RECOMMENDATION: To show the content of a page to a specific segment of users, you can set permissions per role for the whole page, instead for specific widgets. Thus, the page content is cached and logged in users experience fast loading times.
Alternatively, you can implement personalization per widget per user role, as well. Thus, you can leverage standard output caching on personalized content for specific user segments.
For more information, see Personalize widgets.
- Enable Wait for page OutputCache to fill setting.
If you do this, the page will be served only once before its output cache is generated. If another request comes meanwhile, it will wait to be served from the cache. If not selected, the page will be served directly from database to many requests, causing compilation every time until it gets into the cache.
To configure, navigate to Administration » Settings » Advanced » System » Output Cache Settings.
- Remove the
Session_Start method from the
If you do not use the
Session_Start method, comment it out. Even if the method is empty, it causes session generation. This also generates the
ASP.NET_SessionId cookie. This can cause issues with compatibility with CDN's and can cause the output cache to be invalidated.