Modules/businessdev.ALbuild.Containers/Private/Set-BcArtifactLastUse.ps1

function Set-BcArtifactLastUse {
    <#
    .SYNOPSIS
        Stamps a cached artifact version as in use right now.
 
    .DESCRIPTION
        Records the moment a version was handed to a build, so the supersede prune can tell "superseded"
        from "superseded but somebody is still reading it". Windows disables last-access timestamps by
        default and the folder's LastWriteTime only says when it was extracted, so the stamp has to be
        written explicitly.
 
        Best-effort: a cache on a read-only share, or a race with another stamp, must never fail the
        build that only wanted the artifact path.
 
    .PARAMETER VersionFolder
        The <root>\<type>\<version> folder to stamp.
    #>

    [CmdletBinding()]
    param(
        [Parameter(Mandatory)] [ValidateNotNullOrEmpty()] [string] $VersionFolder
    )

    try {
        if (-not (Test-Path -LiteralPath $VersionFolder)) { return }
        $marker = Join-Path -Path $VersionFolder -ChildPath '.albuild-lastuse'
        Set-Content -LiteralPath $marker -Value (Get-Date).ToString('o') -Encoding ASCII -Force -ErrorAction Stop
    }
    catch {
        Write-Verbose "Could not stamp artifact use in '$VersionFolder': $($_.Exception.Message)"
    }
}