Recipes by Category

App Distribution (2) Bundle logic, interface and services for distribution. App Logic (37) The Apex programming language, workflow and formulas for logic. Collaboration (5) The Salesforce Chatter collaboration platform. Database (29) Data persistence, reporting and analytics. Integration (33) Web Service APIs and toolkits for integration. Security (9) Platform, application and data security. Tools (4) tooling User Interface (36) Visualforce MVC and metadata-drive user interfaces. Web Sites (12) Public web sites and apps with optional user registration and login.
Beta Feedback
Cookbook Home » Cache Visualforce pages on Sites

Cache Visualforce pages on Sites

Post by Jon Mountjoy  (2010-07-28)

Status: Verified
Level: novice

Practice Motivation

Use the global content distribution network caching feature of Sites to dramatically increase the performance of your Sites-based websites. It will also help you avoid Sites limits.


A public Visualforce page on a Site may make a number of queries, or even call outs to external web sites. This will slow down the rendering of the page. You can ensure that page is rendered much snappier by configuring the page to be cached.

To cache a page, set the cache attribute on the page to true, and set a value (in seconds) in the expires attribute. For example:

 <apex:page cache="true" expires="600">
    rest of page goes here

This will also decrease the service request time - the time spends rendering the page. As the service request time is a limit on which a deployed Site is measured, caching will help reduce this limit.

Discussion uses a global content distribution network. For example, the first user to access the page in the UK will probably not hit the cache. Subsequent calls by that user, or any others in the UK, will hit the cache (provided that the page cache hasn’t expired). Use static resources to ensure other items your page references are also cached - like CSS and image files


Recipe Activity - Please Log in to write a comment

Be sure to use caution when caching pages that may display private information. For example let's pretend you have a webform that creates a cookie and then autofills the form based on the cookie values when a user returns in the future. A page like this should not be cached.

What will happen is if the page is not currently cached the associated Apex will run and autofill the form. This data will then reside in the form for the next 10 minutues or the length of the expires time. Anyone that visits the page while it is cached during this time will see the values that were populated by the Apex cookie values.

by Jason Venable  (2010-09-16)


Vote to Verify a Recipe

Verifying a recipe is a way to give feedback to others and broaden your own understanding of the capabilities on When you verify a recipe, please make sure the code runs, and the functionality solves the articulated problem as expected.

Please make sure:
  • All the necessary pieces are mentioned
  • You have tested the recipe in practice
  • Have sent any suggestions for improvements to the author

Please Log in to verify a recipe

You have voted to verify this recipe.