Create a cache profile in SharePoint using PowerShell

I have been looking for a way to create a new cache profile in SharePoint using Powershell. This profile can be used in the Page Output cache.
I noticed that cache profiles are stored in a list called “Cache Profiles” and implement the “Page Output Cache” content type.

So, creating a new profile shouldn’t be that difficult.

$site = Get-SPSite $rootURL
$web = Get-SPWeb $rootURL
$list = $web.Lists["Cache Profiles"]
$ctCacheProfile = $list.ContentTypes["Page Output Cache"]
$profile = $list.Items.Add()
$profile["ContentTypeId"] = $ctCacheProfile.Id
$profile.Update()

$profile["Title"] = "My Custom Cache Profile"
$profile["Display Name"] = "My Custom Cache Profile"
$profile["Description"] = "My Custom Cache Profile"
$profile["Perform ACL Check"] = $true
$profile["Enabled"] = $true
$profile["Duration"] = "180"
$profile["Check for Changes"] = $false
$profile["Vary by Custom Parameter"] = "Browser"
$profile["Vary by HTTP Header"] = ""
$profile["Vary by Query String Parameters"] = ""
$profile["Vary by User Rights"] = $true
$profile["Cacheability"] = "ServerAndPrivate"
$profile["Safe for Authenticated Use"] = $true
$profile["Allow writers to view cached content"] = $false
$profile.Update()

To add the profile to your Page Output Cache and enable the cache, you can use the following code:

$cacheSettings = New-Object Microsoft.SharePoint.Publishing.SiteCacheSettingsWriter($rootURL)
$cacheSettings.EnableCache = $true
$cacheSettings.SetAuthenticatedPageCacheProfileId($site, $profile.ID)
$cacheSettings.Update()
VN:F [1.9.14_1148]
Rating: 0 (from 0 votes)

Leave a Reply

Your email address will not be published. Required fields are marked *

*


− 4 = 1

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>