Created
March 7, 2023 10:06
-
-
Save suhrab/a8b597f647be86c0e1ad6c45a06fc1e2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using ZiggyCreatures.Caching.Fusion; | |
namespace WorkerService8; | |
public class Program | |
{ | |
public static async Task Main(string[] args) | |
{ | |
IHost host = Host.CreateDefaultBuilder(args) | |
.ConfigureServices(services => | |
{ | |
services.AddFusionCache(); | |
}) | |
.Build(); | |
var cache = host.Services.GetRequiredService<IFusionCache>(); | |
await cache.GetOrSetAsync("key1", cacheFactoryGood, cacheSetup); | |
// local functions | |
static Task<CacheItem> cacheFactoryGood(CancellationToken cancellationToken) | |
{ | |
Console.WriteLine("cacheFactoryGood fired"); | |
return Task.FromResult(new CacheItem()); | |
} | |
static void cacheSetup(FusionCacheEntryOptions opts) | |
{ | |
opts.Duration = TimeSpan.MaxValue; | |
} | |
} | |
} | |
internal class CacheItem | |
{ | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment