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