Modules/businessdev.ALbuild.Core/Private/Save-ALbuildLicenseCacheEntry.ps1

function Save-ALbuildLicenseCacheEntry {
    <#
    .SYNOPSIS
        Persists (or clears) the last-verified license entry for a tenant, backing the offline grace
        window. Best-effort: a write failure is logged but never breaks a license check.
 
    .PARAMETER TenantId
        Azure DevOps organization / collection id the cache is keyed by.
 
    .PARAMETER Status
        The verified status (e.g. 'OK'). Stamped with the current time as VerifiedAt.
 
    .PARAMETER IsTrial
        Whether the verified license is a trial.
 
    .PARAMETER ExpiresOn
        Trial expiry, if any.
 
    .PARAMETER Clear
        Remove any cached entry for the tenant (used when the service explicitly denies the license,
        so a revoked license cannot keep working through the grace window).
    #>

    [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseShouldProcessForStateChangingFunctions', '',
        Justification = 'Writes a best-effort machine-local cache file; not a user-facing state change.')]
    [CmdletBinding()]
    param(
        [Parameter(Mandatory)] [string] $TenantId,
        [string] $Status,
        [bool] $IsTrial,
        [Nullable[datetime]] $ExpiresOn,
        [switch] $Clear
    )

    try {
        $dir = Join-Path (Get-ALbuildConfig -Name 'BaseFolder') 'license-cache'
        $file = Join-Path $dir ("$TenantId.json")

        if ($Clear) {
            if (Test-Path -LiteralPath $file) { Remove-Item -LiteralPath $file -Force -ErrorAction Stop }
            return
        }

        if (-not (Test-Path -LiteralPath $dir)) { New-Item -ItemType Directory -Force -Path $dir | Out-Null }
        $entry = [ordered]@{
            Status     = $Status
            IsTrial    = $IsTrial
            ExpiresOn  = if ($ExpiresOn) { $ExpiresOn.Value.ToString('o') } else { $null }
            VerifiedAt = (Get-Date).ToUniversalTime().ToString('o')
        }
        $entry | ConvertTo-Json | Set-Content -LiteralPath $file -Encoding UTF8 -ErrorAction Stop
    }
    catch {
        Write-Verbose "Could not write the license cache for tenant '$TenantId': $($_.Exception.Message)"
    }
}