ResultTtl<TResult>
using System;
using System.Runtime.CompilerServices;
namespace Polly.Caching
{
public class ResultTtl<[System.Runtime.CompilerServices.Nullable(2)] TResult> : ITtlStrategy<TResult>
{
[System.Runtime.CompilerServices.Nullable(new byte[] {
1,
1,
2
})]
private readonly Func<Context, TResult, Ttl> _ttlFunc;
public ResultTtl([System.Runtime.CompilerServices.Nullable(new byte[] {
1,
2
})] Func<TResult, Ttl> ttlFunc)
{
if (ttlFunc == null)
throw new ArgumentNullException("ttlFunc");
_ttlFunc = ((Context _, TResult result) => ttlFunc(result));
}
public ResultTtl([System.Runtime.CompilerServices.Nullable(new byte[] {
1,
1,
2
})] Func<Context, TResult, Ttl> ttlFunc)
{
if (ttlFunc == null)
throw new ArgumentNullException("ttlFunc");
_ttlFunc = ttlFunc;
}
[System.Runtime.CompilerServices.NullableContext(1)]
public Ttl GetTtl(Context context, [System.Runtime.CompilerServices.Nullable(2)] TResult result)
{
return _ttlFunc(context, result);
}
}
}