Last active
April 30, 2024 07:09
-
-
Save keyan1603/53aebac421ef354382ad83e52f9b024a to your computer and use it in GitHub Desktop.
Get Sitecore SXA Site Cache Settings
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Import-Function Get-AllSxaSite | |
$sites = New-Object System.Collections.ArrayList | |
class ItemDetail { | |
[string]$ID | |
[string]$Name | |
[string]$Path | |
[bool]$Cacheable | |
[bool]$ClearOnIndexUpdate | |
[string]$CacheClearingBehavior | |
} | |
$ItemDetails = New-Object Collections.Generic.List[ItemDetail] | |
Get-AllSxaSite | % { $sites.Add($_) } >> $null | |
foreach ($site in $sites) | |
{ | |
$itemPath = $site.Paths.FullPath + "/Presentation/Cache Settings/Component Cache Settings" | |
if(Test-Path -Path $itemPath) | |
{ | |
$Item = Get-Item -Path $itemPath | |
$newItemDetail = [ItemDetail]::new() | |
$newItemDetail.ID = $Item.ID | |
$newItemDetail.Name = $Item.Name | |
$newItemDetail.Path = $itemPath | |
$newItemDetail.Cacheable = $Item.Cacheable | |
$newItemDetail.ClearOnIndexUpdate = $Item.ClearOnIndexUpdate | |
$newItemDetail.CacheClearingBehavior = $Item.CacheClearingBehavior | |
$ItemDetails.Add($newItemDetail) | |
} | |
else | |
{ | |
#in case if no item found, try to get the item through Template id | |
$itemPath = $site.Paths.FullPath + "/Presentation/Cache Settings" | |
$Query = $itemPath | |
# sanitise content | |
$contentOfQuery = $Query -split '/' | |
foreach($content in $contentOfQuery) | |
{ | |
if($content.Contains("-")) | |
{ | |
$Query = $Query.Replace("/" + $content + "/", "/#" + $content + "#/") | |
} | |
} | |
$Query = $Query.Replace("##", "#") | |
$Query = $Query + "/*[@@templateid='{E24DE305-C60F-47D1-97C0-DE121D6831D0}']" | |
$ElseItem = Get-Item -Path "master:" -Query $Query | |
if($ElseItem -ne $null) | |
{ | |
$newItemDetail = [ItemDetail]::new() | |
$newItemDetail.ID = $ElseItem.ID | |
$newItemDetail.Name = $ElseItem.Name | |
$newItemDetail.Path = $itemPath + "/" + $ElseItem.Name | |
$newItemDetail.Cacheable = $ElseItem.Cacheable | |
$newItemDetail.ClearOnIndexUpdate = $ElseItem.ClearOnIndexUpdate | |
$newItemDetail.CacheClearingBehavior = $ElseItem.CacheClearingBehavior | |
$ItemDetails.Add($newItemDetail) | |
} | |
} | |
} | |
$ItemDetails | Show-ListView |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment