public Task <CacheResult <T> > Fetch <T>(string cache, string key) { string fullKey = GetFullKey(cache, key); CacheItem item = memoryCache.GetCacheItem(fullKey); CacheResult <T> result; if (item != null) { if (typeof(T).IsAssignableFrom(item.Value.GetType())) { result = CacheResult <T> .Found((T)item.Value); } else { result = CacheResult <T> .NotFound(); } } else { result = CacheResult <T> .NotFound(); } return(Task.FromResult(result)); }
public async Task <TValue> Fetch() { CacheResult <TValue> resultFromCache = await provider.Fetch <TValue>(CacheName, "Key"); if (resultFromCache.FoundInCache) { return(resultFromCache.Value); } else { TValue value; value = await fetchFromApi(); await provider.Add(CacheName, "Key", value, Duration); return(value); } }
public async Task <TValue> Fetch(TKey key) { string hash = hashKey(key); CacheResult <TValue> resultFromCache = await provider.Fetch <TValue>(CacheName, hash); if (resultFromCache.FoundInCache) { return(resultFromCache.Value); } else { TValue value; value = await fetchFromApi(key); await provider.Add(CacheName, hash, value, Duration); return(value); } }