Monday, 11 June 2012

Caching in SharePoint 2010

SharePoint Server 2010 provides three types of caches that help improve the speed at which Web pages load in the browser: the BLOB cache, the page output cache, and the object cache. 

BLOB cache

SharePoint Server 2010 provides a disk-based cache that stores files that are used by Web pages to help them load quickly in the browser, and reduces the load on the database server when it uses those files. These files are known as binary large objects (BLOBs), and the cache is known as the BLOB cache. The BLOB cache is stored directly on the hard disk drive of a front-end Web server computer. The first time that a Web page is called, these files are copied from the database to the cache on the server hard disk drive, and all subsequent requests for those files are then served from the hard disk drive cache of the server. By default, the BLOB cache is off and must be enabled to use the functionality it provides. When you enable the BLOB cache on your front-end Web server, you reduce the load on the SharePoint Server 2010 database server created by read requests from Web browsers.

how to enable BLOB cache in a web application,

Open web application's web.config file in note pad and find  the following line: 
<BlobCache location="" path="\.(gif|jpg|jpeg|jpe|jfif|bmp|dib|tif|tiff|ico|png|wdp|hdp|css|js|asf|avi|flv|m4v|mov|mp3|mp4|mpeg|mpg|rm|rmvb|wma|wmv)$" maxSize="10" enabled="false" />


Modify the following attributes
location – the path to the directory where the blob files stores in the disk.
Path -- To add or remove file types from the list of file types to be cached, for the path attribute, modify the regular expression to include or remove the appropriate file extension. If you add file extensions, make sure to separate each file type with a pipe (|), as shown in this line of code.
maxSize -- To change the size of the cache, type a new number for maxSize. The size is expressed in gigabytes (GB), and 10 GB is the default.


To enable the BLOB cache, change the enabled attribute, from "false" to "true".

Now save web.config file and close it.

Example:

<BlobCache location="C:\BlobCache\14" path="\.(gif|jpg|jpeg|jpe|jfif|bmp|dib|tif|tiff|ico|png|wdp|hdp|css|js|asf|avi|flv|m4v|mov|mp3|mp4|mpeg|mpg|rm|rmvb|wma|wmv)$" maxSize="10" enabled="true" />


now i uploaded one image file and placed it in home.aspx



now this page contain one image and this image is cached when the first time we request that page and saved that image in the following directory "C:\BlobCache\14\" and it is in home page so home page is available in site assests library so it create one folder in the cache location and also it create another folder for site pages , in that it create another folder with the page name and in that folder it will save all images which are placed in the home page.



NOTE:
Flush output cache
In some situations, you need to flush the output cache. You can do this by using the following PowerShell commands

$webApp = Get-SPWebApplication "<< your site URL >>"
[Microsoft.SharePoint.Publishing.PublishingCache]::FlushBlobCache($webApp)
Write-Host "Flushed the BLOB cache for:" $webApp


open notepad and copy above three lines of code and save it as "blobflush.ps1"( i saved in "C" drive) and now open powershell window and run this script.





after flush


Reference here

Page output cache profiles

Cache profile settings can be configured in the user interface at the site collection level by a site collection administrator, as well as at the Web application level by an administrator on the front-end Web server. The page output cache must be enabled at the site collection level before page output cache profiles can be configured at either the site collection level or Web application level. If page output cache profiles are enabled at the Web application level, the settings specified in Web.config will be used for all page output cache profiles, overriding any values that have been entered through the user interface at the site collection level.

Note:


To use the page output cache and the associated cache profile settings, you must be using the Publishing feature on your site.


How to enable OutPut Cache profiles,

Open the web.config of webapplication in Notepad file, find the following line: <OutputCacheProfiles useCacheProfileOverrides="false" varyByHeader="" varyByParam="*"  varyByCustom="" varyByRights="true" cacheForEditRights="false" />

To enable the cache profile at the Web application level, change the useCacheProfileOverrides attribute, from "false" to "true".

To enable output caching for a site collection

  1. Navigate to the root Web site of the site collection. On the Site Actions menu, click Site Settings.
  2. In the Site Collection Administration section, select Site collection output cache.
  3. To enable output caching for this site collection, select Enable output cache.
  4. Choose a cache profile for anonymous users from the Anonymous Cache Profile list. This profile is applied when anonymous users access a site in this site collection.
  5. Choose a cache profile for authenticated users from the Authenticated Cache Profile list. This profile is applied when authenticated users access a site in this site collection.
  6. Choose Page Output Cache Policy options:
    • If publishing sites can use a different output cache profile, select Publishing sites can use a different page output cache profile.
    • If page layouts can use a different output cache profile, select Page layouts can use a different page output cache profile.
  7. If you want to display additional cache information on pages in this site collection, including the date and time that page contents were last rendered, select Enable debug cache information on pages.
  8. Click OK.

To enable output caching for a site

  1. Navigate to the root Web site of the site collection. On the Site Actions menu, click Site Settings.
  2. In the Site Administration section, select Site output cache.
  3. Choose an Anonymous Cache Profile option:
    • If you want to inherit a cache profile, click Inherit.
    • If you want to choose a cache profile from those currently available, select Select a page output cache profile.
  4. If you want to apply these settings to all subsites of this root Web site, select Apply these settings to all sub-sites.
  5. Click OK.

To create a new cache profile

  1. Navigate to the root Web site of the site collection. On the Site Actions menu, click Site Settings.
  2. In the Site Collection Administration section, select Site collection cache profiles.
  3. Click New.
  4. Define and create a new cache profile.

Object Cache


What Object cache does is stores metadata about SharePoint Server objects (like SPWeb, SPSite, SPList, etc.) on the WFEs. When a page is rendered, if there is data that needs to be retrieved through these objects, the SQL Server will not be hit. Features of SharePoint that uses Object cache are publishing, content query web part, navigation, search query box and metadata navigation.

Configuring object cache settings


The object cache settings can be configured at the site collection level in the user interface by a site collection administrator, and is on by default. The maximum cache size can be configured at the Web application level on the front-end Web server to place a restriction on the maximum amount of memory that the cache will use for all site collections. For example, individual site collections might have the object cache set at 100 MB, while the Web application might be set at 1 GB. In this case, no more than 1 GB of memory will be used by all the caches on the server.


No comments:

Post a Comment