Home Gitesh Portfolio Blog About Me Gallery Contact

Sitecore: Powershell query to find all cached vs non-cached rendering components

In this blog you will find all cached vs non-cached rendering components with the help of powershell query. Before you go live on a site it is very important to see whether caching is properly turned ON or not for your components.



All Cached Rendering Components


Import-Function -Name ConvertTo-Xlsx

$cacheableRendering =  Get-ChildItem -Path "master:\layout\Renderings" -Recurse | 
    Where-Object { $_.TemplateName -like "*rendering*" -And  $_.Cacheable -eq "1" } | 
    Select-Object -Property Name, ID, TemplateName,  Cacheable, ClearOnIndexUpdate, VaryByData , VaryByDevice , VaryByLogin , VaryByParm, VaryByQueryString, VaryByUser | 
    Sort-Object -Property Name 
    
[byte[]]$outobject =  $cacheableRendering | ConvertTo-Xlsx 

Out-Download -Name "report_allCached_RenderingComponents.xlsx" -InputObject $outobject

All non-Cached Rendering Components


Import-Function -Name ConvertTo-Xlsx

$notCacheableRendering =  Get-ChildItem -Path "master:\layout\Renderings" -Recurse | 
    Where-Object { $_.TemplateName -like "*rendering*" -And  $_.Cacheable -ne "1" } | 
    Select-Object -Property Name, ID, TemplateName,  Cacheable, ClearOnIndexUpdate, VaryByData , VaryByDevice , VaryByLogin , VaryByParm, VaryByQueryString, VaryByUser | 
    Sort-Object -Property Name
    
[byte[]]$outobject =  $cacheableRendering | ConvertTo-Xlsx 

Out-Download -Name "report_allNonCached_RenderingComponents.xlsx" -InputObject $outobject

All Rendering Component With Cache Settings


Import-Function -Name ConvertTo-Xlsx

$allRendering =  Get-ChildItem -Path "master:\layout\Renderings" -Recurse | 
    Where-Object { $_.TemplateName -like "*rendering*" } | 
    Select-Object Name, ID, TemplateName,  Cacheable, ClearOnIndexUpdate, VaryByData , VaryByDevice , VaryByLogin , VaryByParm, VaryByQueryString, VaryByUser | 
    Sort-Object -Property Name
    
[byte[]]$outobject =  $allRendering | ConvertTo-Xlsx 

Out-Download -Name "report_allRenderingComponents.xlsx" -InputObject $outobject

Posted: 14/04/2022 5:13:39 p.m. by Gitesh Shah | with 0 comments