@@ -39,14 +39,12 @@ function Invoke-DscCacheRefresh {
39
39
40
40
$refreshCache = $false
41
41
42
- $cacheFileSuffix = " .json"
42
+ $cacheFilePath = Join-Path $ env: LocalAppData " dsc " " PSAdapterCache .json"
43
43
if ($PSVersionTable.PSVersion.Major -le 5 ) {
44
- $cacheFileSuffix = " -v5 .json"
44
+ $cacheFilePath = Join-Path $ env: LocalAppData " dsc " " WindowsPSAdapterCache .json"
45
45
}
46
-
47
- $cacheFilePath = Join-Path $env: LocalAppData " dscv3classcache$cacheFileSuffix "
48
46
if ($IsLinux -or $IsMacOS ) {
49
- $cacheFilePath = Join-Path $env: HOME " . dsc" " dscv3classcache $cacheFileSuffix "
47
+ $cacheFilePath = Join-Path $env: HOME " dsc" " PSAdapterCache.json "
50
48
}
51
49
52
50
if (Test-Path $cacheFilePath ) {
@@ -90,7 +88,7 @@ function Invoke-DscCacheRefresh {
90
88
$trace = @ {' Debug' = " Checking cache for stale PSModulePath" } | ConvertTo-Json - Compress
91
89
$host.ui.WriteErrorLine ($trace )
92
90
93
- $m = $env: PSModulePath -split [IO.Path ]::PathSeparator | % {Get-ChildItem - Directory - Path $_ - ea SilentlyContinue}
91
+ $m = $env: PSModulePath -split [IO.Path ]::PathSeparator | % {Get-ChildItem - Directory - Path $_ - Depth 1 - ea SilentlyContinue}
94
92
95
93
$hs_cache = [System.Collections.Generic.HashSet [string ]]($cache.PSModulePaths )
96
94
$hs_live = [System.Collections.Generic.HashSet [string ]]($m.FullName )
@@ -205,7 +203,7 @@ function Invoke-DscCacheRefresh {
205
203
206
204
# fill in resource files (and their last-write-times) that will be used for up-do-date checks
207
205
$lastWriteTimes = @ {}
208
- Get-ChildItem - Recurse - Path $dscResource.ParentPath | % {
206
+ Get-ChildItem - Recurse - File - Path $dscResource.ParentPath - Include " *.ps1 " , " *.psd1 " , " *psm1 " , " *.mof " - ea SilentlyContinue | % {
209
207
$lastWriteTimes.Add ($_.FullName , $_.LastWriteTime )
210
208
}
211
209
@@ -218,14 +216,15 @@ function Invoke-DscCacheRefresh {
218
216
219
217
[dscResourceCache ]$cache = [dscResourceCache ]::new()
220
218
$cache.ResourceCache = $dscResourceCacheEntries
221
- $m = $env: PSModulePath -split [IO.Path ]::PathSeparator | % {Get-ChildItem - Directory - Path $_ - ea SilentlyContinue}
219
+ $m = $env: PSModulePath -split [IO.Path ]::PathSeparator | % {Get-ChildItem - Directory - Path $_ - Depth 1 - ea SilentlyContinue}
222
220
$cache.PSModulePaths = $m.FullName
223
221
224
222
# save cache for future use
225
223
# TODO: replace this with a high-performance serializer
226
224
$trace = @ {' Debug' = " Saving Get-DscResource cache to '$cacheFilePath '" } | ConvertTo-Json - Compress
227
225
$host.ui.WriteErrorLine ($trace )
228
- $cache | ConvertTo-Json - Depth 90 | Out-File $cacheFilePath
226
+ $jsonCache = $cache | ConvertTo-Json - Depth 90
227
+ New-Item - Force - Path $cacheFilePath - Value $jsonCache - Type File | Out-Null
229
228
}
230
229
231
230
return $dscResourceCacheEntries
0 commit comments