<PackageReference Include="Polly" Version="8.3.1" />

SlidingTtl

public class SlidingTtl : ITtlStrategy, ITtlStrategy<object>
Defines a ttl strategy which will cache items with a sliding ttl.
using System; using System.Runtime.CompilerServices; namespace Polly.Caching { public class SlidingTtl : ITtlStrategy, ITtlStrategy<object> { private readonly Ttl ttl; public SlidingTtl(TimeSpan slidingTtl) { if (slidingTtl < TimeSpan.Zero) throw new ArgumentOutOfRangeException("slidingTtl", "The ttl for items to cache must be greater than zero."); ttl = new Ttl(slidingTtl, true); } [System.Runtime.CompilerServices.NullableContext(1)] public Ttl GetTtl(Context context, [System.Runtime.CompilerServices.Nullable(2)] object result) { return ttl; } } }