/// <summary> /// Get the value of type <typeparamref name="TValue"/> in the cache for the specified <paramref name="key"/>: if not there, the <paramref name="factory"/> will be called and the returned value saved according with the <see cref="FusionCacheEntryOptions"/> resulting by calling the provided <paramref name="setupAction"/> lambda. /// </summary> /// <typeparam name="TValue">The type of the value in the cache.</typeparam> /// <param name="cache">The <see cref="IFusionCache"/> instance.</param> /// <param name="key">The cache key which identifies the entry in the cache.</param> /// <param name="factory">The function which will be called if the value is not found in the cache.</param> /// <param name="setupAction">The setup action used to further configure the newly created <see cref="FusionCacheEntryOptions"/> object, automatically created by duplicating <see cref="FusionCacheOptions.DefaultEntryOptions"/>.</param> /// <param name="token">An optional <see cref="CancellationToken"/> to cancel the operation.</param> /// <returns>The value in the cache, either already there or generated using the provided <paramref name="factory"/> .</returns> public static Task <TValue> GetOrSetAsync <TValue>(this IFusionCache cache, string key, Func <CancellationToken, Task <TValue> > factory, Action <FusionCacheEntryOptions> setupAction, CancellationToken token = default) { return(cache.GetOrSetAsync <TValue>(key, factory, cache.CreateEntryOptions(setupAction), token)); }
/// <summary> /// Get the value of type <typeparamref name="TValue"/> in the cache for the specified <paramref name="key"/>: if not there, the <paramref name="factory"/> will be called and the returned value saved according with the <paramref name="duration"/> provided. /// </summary> /// <typeparam name="TValue">The type of the value in the cache.</typeparam> /// <param name="cache">The <see cref="IFusionCache"/> instance.</param> /// <param name="key">The cache key which identifies the entry in the cache.</param> /// <param name="factory">The function which will be called if the value is not found in the cache.</param> /// <param name="duration">The value for the newly created <see cref="FusionCacheEntryOptions.Duration"/> property, automatically created by duplicating <see cref="FusionCacheOptions.DefaultEntryOptions"/>.</param> /// <param name="token">An optional <see cref="CancellationToken"/> to cancel the operation.</param> /// <returns>The value in the cache, either already there or generated using the provided <paramref name="factory"/> .</returns> public static Task <TValue> GetOrSetAsync <TValue>(this IFusionCache cache, string key, Func <CancellationToken, Task <TValue> > factory, TimeSpan duration, CancellationToken token = default) { return(cache.GetOrSetAsync <TValue>(key, factory, cache.DefaultEntryOptions.Duplicate(duration), token)); }