Home

Does Util.Cache() reliably cache the results of asynchronous functions?

edited January 2020

Title. With this test, it does seem to work, but should I expect it to?

async Task Main()
{
    $"Running now: {DateTime.Now}".Dump();
    var date = await Util.Cache(async () => await GetDate(), "now");
    date.Dump();

    async Task<DateTime> GetDate()
    {
        await Task.Delay(3000);
        return DateTime.Now;
    }
}

Comments

Sign In or Register to comment.