Last active
April 26, 2022 10:00
-
-
Save bjorn-einar-bjartnes-4ss/410124e1dddd12732c312cc71b7c1985 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
async Task<int> GetMe(CancellationToken ct) { | |
await Task.Delay(1000,ct); | |
return 5; | |
} | |
async Task Main() | |
{ | |
var memoryCacheOptions = new MemoryCacheOptions(); | |
var cache = new MemoryCache(memoryCacheOptions); | |
var cts = new CancellationTokenSource(); | |
// Someone triggers the cache | |
cache.Set("maybe 5", GetMe(cts.Token)); | |
// And close the connection | |
cts.Cancel(); | |
// Then someone later wants the result | |
var getTask = cache.Get<Task<int>>("maybe 5"); | |
var whatIsHere = await getTask; | |
whatIsHere.Dump(); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment