/// <summary> /// Put the <paramref name="value"/> in the cache for the specified <paramref name="key"/> with the <see cref="FusionCacheEntryOptions"/> resulting by calling the provided <paramref name="setupAction"/> lambda. If a value is already there it will be overwritten. /// </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="value">The value to put 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> public static void Set <TValue>(this IFusionCache cache, string key, TValue value, Action <FusionCacheEntryOptions> setupAction, CancellationToken token = default) { cache.Set <TValue>(key, value, cache.CreateEntryOptions(setupAction), token); }
/// <summary> /// Put the <paramref name="value"/> in the cache for the specified <paramref name="key"/> with the provided <paramref name="duration"/>. If a value is already there it will be overwritten. /// </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="value">The value to put 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> public static void Set <TValue>(this IFusionCache cache, string key, TValue value, TimeSpan duration, CancellationToken token = default) { cache.Set <TValue>(key, value, cache.DefaultEntryOptions.Duplicate(duration), token); }