Added caching of Get-DscResource results to PSDscAdapter, reducing execution time for classic PS DSC resources:
Before:
PS C:\DSCv3> (Measure-Command {dsc.exe resource list -a "Microsoft.DSC/PowerShell"}).TotalSeconds
8.0908457
PS C:\DSCv3> (Measure-Command {"{'Name':'TestPSRepository1'}" | dsc resource set -r 'PSTestModule/TestPSRepository'}).TotalSeconds
12.1434988
After:
PS C:\DSCv3> (Measure-Command {dsc.exe resource list -a "Microsoft.DSC/PowerShell"}).TotalSeconds
2.3765501
PS C:\DSCv3> (Measure-Command {"{'Name':'TestPSRepository1'}" | dsc resource set -r 'PSTestModule/TestPSRepository'}).TotalSeconds
6.6152832
1) Cache location is in user-specific folders:
on Windows - $env:LocalAppData\dsc\PSAdapterCache.json
for WindowsPS adapter - $env:LocalAppData\dsc\WindowsPSAdapterCache.json
on Linux/Mac - $env:HOME/.dsc/PSAdapterCache.json
2) Checks for stale cache:
a) cache contains every subfolder (+1 level deep to account for new module versions) in PSModulePath (i.e. all visible module paths), which is analyzed when cache is accessed.
I.e. if PSModulePath changes or a module is added/removed from existing PSModulePath, that is detected, and cache is rebuilt.
b) for each resource type cache also contains all "*.ps1","*.psd1","*psm1","*.mof" files under $dscResource.ParentPath and their LastWrite timestamps. On accessing the cache LastWrite times of live files is compared with those in cache and cache is rebuilt if they are different.
PR Summary
Added caching of
Get-DscResource
results toPSDscAdapter
, reducing execution time for classic PS DSC resources:Before:
After:
1) Cache location is in user-specific folders: on Windows -
$env:LocalAppData\dsc\PSAdapterCache.json
for WindowsPS adapter -$env:LocalAppData\dsc\WindowsPSAdapterCache.json
on Linux/Mac -$env:HOME/.dsc/PSAdapterCache.json
2) Checks for stale cache: a) cache contains every subfolder (+1 level deep to account for new module versions) in
PSModulePath
(i.e. all visible module paths), which is analyzed when cache is accessed. I.e. ifPSModulePath
changes or a module is added/removed from existingPSModulePath
, that is detected, and cache is rebuilt. b) for each resource type cache also contains all"*.ps1","*.psd1","*psm1","*.mof"
files under$dscResource.ParentPath
and theirLastWrite
timestamps. On accessing the cacheLastWrite
times of live files is compared with those in cache and cache is rebuilt if they are different.