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

ResultTtl<TResult>

public class ResultTtl<TResult> : ITtlStrategy<TResult>
Defines a ttl strategy which can calculate a duration to cache items dynamically based on the execution context and result of the execution.
using System; namespace Polly.Caching { public class ResultTtl<TResult> : ITtlStrategy<TResult> { private readonly Func<Context, TResult, Ttl> _ttlFunc; public ResultTtl(Func<TResult, Ttl> ttlFunc) { if (ttlFunc == null) throw new ArgumentNullException("ttlFunc"); _ttlFunc = ((Context context, TResult result) => ttlFunc(result)); } public ResultTtl(Func<Context, TResult, Ttl> ttlFunc) { if (ttlFunc == null) throw new ArgumentNullException("ttlFunc"); _ttlFunc = ttlFunc; } public Ttl GetTtl(Context context, TResult result) { return _ttlFunc(context, result); } } }