Example #1
0
    public static TValue Read <TKey, TValue>(this IKeyedCache <TKey, TValue> cache, TKey key, Func <TValue> source)
    {
        var item = cache.TryRead(key);

        if (item == null)
        {
            item = source();

            cache.Write(key, item);
        }

        return(item);
    }
Example #2
0
    public static async Task <TValue> ReadAsync <TKey, TValue>(this IKeyedCache <TKey, TValue> cache, TKey key, Func <Task <TValue> > source)
    {
        var item = cache.TryRead(key);

        if (item == null)
        {
            item = await source();

            cache.Write(key, item);
        }

        return(item);
    }