From 02e429d99dfe06ececdcf0d2b389b6cd2c0ea0b7 Mon Sep 17 00:00:00 2001 From: rbalsleyMSFT <53497092+rbalsleyMSFT@users.noreply.github.com> Date: Thu, 22 Jan 2026 17:26:49 -0800 Subject: [PATCH] Adds TTL-based refresh for Surface cache MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Treats driver index cache older than 7 days as stale to trigger re-downloads and avoid outdated metadata. Improves resiliency by falling back to a refresh when the cache timestamp can’t be read, and adds clearer logging for cache age and refresh decisions. --- .../FFU.Common.Drivers.Microsoft.psm1 | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/FFUDevelopment/FFU.Common/FFU.Common.Drivers.Microsoft.psm1 b/FFUDevelopment/FFU.Common/FFU.Common.Drivers.Microsoft.psm1 index 03555c7..2151752 100644 --- a/FFUDevelopment/FFU.Common/FFU.Common.Drivers.Microsoft.psm1 +++ b/FFUDevelopment/FFU.Common/FFU.Common.Drivers.Microsoft.psm1 @@ -37,6 +37,9 @@ function Import-SurfaceDriverIndexCache { ) $cachePath = Get-SurfaceDriverIndexCachePath -DriversFolder $DriversFolder + + # Surface cache TTL (7 days): treat stale caches as missing so we re-download Sources A/B/C as needed. + $cacheTtlDays = 7 if (-not (Test-Path -Path $cachePath -PathType Leaf)) { return [pscustomobject]@{ ModelIndex = @() @@ -45,6 +48,28 @@ function Import-SurfaceDriverIndexCache { } } + try { + $cacheAgeDays = ((Get-Date) - (Get-Item -Path $cachePath -ErrorAction Stop).LastWriteTime).TotalDays + if ($cacheAgeDays -ge $cacheTtlDays) { + WriteLog "Surface cache: Cache file '$cachePath' is older than $cacheTtlDays days ($([math]::Round($cacheAgeDays, 1)) days). Refreshing." + return [pscustomobject]@{ + ModelIndex = @() + SkuIndex = @() + DownloadCenterDetails = @() + } + } + + WriteLog "Surface cache: Loading cached SurfaceDriverIndex.json from '$cachePath' (age: $([math]::Round($cacheAgeDays, 1)) days)." + } + catch { + WriteLog "Surface cache: Failed to read cache timestamp for '$cachePath'. Refreshing. Error: $($_.Exception.Message)" + return [pscustomobject]@{ + ModelIndex = @() + SkuIndex = @() + DownloadCenterDetails = @() + } + } + try { $cache = Get-Content -Path $cachePath -Raw | ConvertFrom-Json -ErrorAction Stop }