SlidingTtl
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;
}
}
}