Skip to content

Instantly share code, notes, and snippets.

@suhrab
Created March 7, 2023 10:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save suhrab/a8b597f647be86c0e1ad6c45a06fc1e2 to your computer and use it in GitHub Desktop.
Save suhrab/a8b597f647be86c0e1ad6c45a06fc1e2 to your computer and use it in GitHub Desktop.
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