This blog post describes how the Sitecore ASP.NET CMS caches the output of individual presentation components. For more information about presentation components, see the Presentation Component Reference Manual on the Sitecore Developer Network (SDN). For more information about caching with Sitecore, see the Cache Configuration Reference on SDN.
The Presentation Component materials on SDN (including the Reference and the Cookbook) describe how you can use Sitecore output caching, but don't describe its internal implementation.
Before undersanding how caching works, remember that Sitecore does not generate pages. Sitecore enhances the process for assembling the control tree that ASP.NET uses to generate pages by binding presentation components to placeholders in layouts and sublayouts.
Sitecore does not cache entire pages, but caches the output of individual components. Each component can generate multiple cache entries under different conditions, such the data source of the rendering, query string parameters and other criteria.
Sitecore uses the following basic approach to insert caching logic into the page generation process:
This might be redundant (especially with my blog post Custom Caching Criteria with the Sitecore ASP.NET CMS), but it seems appropriate to describe how Sitecore determines the key to the cache.
Each presentation component should implement the GetCachingID() method of the Sitecore.Web.UI.WebControl class to return something that identifies the control. The Sitecore.Web.UI.WebControls.Sublayout and Sitecore.Web.UI.WebControls.XslFile controls implement this method to return the path to the .aspx or .xslt file. Your web controls should implement a method such as the following (or implement this in an abstract base class that inherits from Sitecore.Web.UI.WebControl for all of your web controls inherit):
protected override string GetCachingID()
The output cache acts something like a hashtable, but somewhat more complex as you can see from my blog post Schedule Expiration for Output Cache Entries with the Sitecore ASP.NET CMS. Whether adding or retrieving a cache entry, to determine the key to the cache for a control, Sitecore invokes the GetCacheKey() method of the Sitecore.Web.UI.WebControl class, which in turn invokes the GetCachingID() method. If you simply mark a control as cachable, Sitecore uses the result of calling the GetCachingID() method plus a string that identifies the context language as the key for the cache entry. If you select additional VaryBy parameters (as described in the Presentation Component Reference Manual), Sitecore adds additional strings to the key.
See also: sitecoreaustralia.wordpress.com/.../cache-webinar-recording
Not output caching, but... sitecorebasics.wordpress.com/.../
Also not specific to output caching, but possibly relevant: learnsitecore.cmsuniverse.net/.../CachingOverview.aspx
We have used ASP.net Output cache directive on one of the sublayout , however the cache directive has no effect since it always fetches data through code instead of cache. Please suggest as I am stuck on it.