@@ -73,50 +73,52 @@ function Invoke-DscCacheRefresh {
7373 " Filtered DscResourceCache cache is empty" | Write-DscTrace
7474 }
7575 else {
76- " Checking cache for stale entries " | Write-DscTrace
76+ " Checking cache for stale PSModulePath " | Write-DscTrace
7777
78- foreach ( $cacheEntry in $dscResourceCacheEntries ) {
78+ $m = $ env: PSModulePath -split [ IO.Path ]::PathSeparator | % { Get-ChildItem - Directory - Path $_ - Depth 1 - ea SilentlyContinue }
7979
80- $cacheEntry.LastWriteTimes.PSObject.Properties | ForEach-Object {
80+ $hs_cache = [System.Collections.Generic.HashSet [string ]]($cache.PSModulePaths )
81+ $hs_live = [System.Collections.Generic.HashSet [string ]]($m.FullName )
82+ $hs_cache.SymmetricExceptWith ($hs_live )
83+ $diff = $hs_cache
8184
82- if (Test-Path $_.Name ) {
83- $file_LastWriteTime = (Get-Item $_.Name ).LastWriteTimeUtc
84- # Truncate DateTime to seconds
85- $file_LastWriteTime = $file_LastWriteTime.AddTicks ( - ($file_LastWriteTime.Ticks % [TimeSpan ]::TicksPerSecond));
85+ " PSModulePath diff '$diff '" | Write-DscTrace
86+ if ($diff.Count -gt 0 ) {
87+ $refreshCache = $true
88+ # Get all resources
89+ $Module = $null
90+ }
8691
87- $cache_LastWriteTime = [DateTime ]$_.Value
88- # Truncate DateTime to seconds
89- $cache_LastWriteTime = $cache_LastWriteTime.AddTicks ( - ($cache_LastWriteTime.Ticks % [TimeSpan ]::TicksPerSecond));
92+ if (-not $refreshCache ) {
93+ " Checking cache for stale entries" | Write-DscTrace
9094
91- if (-not ($file_LastWriteTime.Equals ($cache_LastWriteTime ))) {
92- " Detected stale cache entry '$ ( $_.Name ) '" | Write-DscTrace
93- $refreshCache = $true
94- break
95- }
96- }
97- else {
98- " Detected non-existent cache entry '$ ( $_.Name ) '" | Write-DscTrace
99- $refreshCache = $true
100- break
101- }
102- }
95+ foreach ($cacheEntry in $dscResourceCacheEntries ) {
10396
104- if ($refreshCache ) { break }
105- }
97+ $cacheEntry.LastWriteTimes.PSObject.Properties | ForEach-Object {
10698
107- if (-not $refreshCache ) {
108- " Checking cache for stale PSModulePath" | Write-DscTrace
99+ if (Test-Path $_.Name ) {
100+ $file_LastWriteTime = (Get-Item $_.Name ).LastWriteTimeUtc
101+ # Truncate DateTime to seconds
102+ $file_LastWriteTime = $file_LastWriteTime.AddTicks ( - ($file_LastWriteTime.Ticks % [TimeSpan ]::TicksPerSecond));
109103
110- $m = $env: PSModulePath -split [IO.Path ]::PathSeparator | % { Get-ChildItem - Directory - Path $_ - Depth 1 - ea SilentlyContinue }
104+ $cache_LastWriteTime = [DateTime ]$_.Value
105+ # Truncate DateTime to seconds
106+ $cache_LastWriteTime = $cache_LastWriteTime.AddTicks ( - ($cache_LastWriteTime.Ticks % [TimeSpan ]::TicksPerSecond));
111107
112- $hs_cache = [System.Collections.Generic.HashSet [string ]]($cache.PSModulePaths )
113- $hs_live = [System.Collections.Generic.HashSet [string ]]($m.FullName )
114- $hs_cache.SymmetricExceptWith ($hs_live )
115- $diff = $hs_cache
108+ if (-not ($file_LastWriteTime.Equals ($cache_LastWriteTime ))) {
109+ " Detected stale cache entry '$ ( $_.Name ) '" | Write-DscTrace
110+ $refreshCache = $true
111+ break
112+ }
113+ }
114+ else {
115+ " Detected non-existent cache entry '$ ( $_.Name ) '" | Write-DscTrace
116+ $refreshCache = $true
117+ break
118+ }
119+ }
116120
117- " PSModulePath diff '$diff '" | Write-DscTrace
118- if ($diff.Count -gt 0 ) {
119- $refreshCache = $true
121+ if ($refreshCache ) { break }
120122 }
121123 }
122124 }
0 commit comments