コード例 #1
0
        /// <summary>
        /// Retrieve cache asynchronously
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="key"></param>
        public async Task <T> GetCacheAsync <T, T2>(T2 key)
        {
            //Check memory cache first
            T memoryValue = await _memoryCachingManager.GetCacheAsync <T, T2>(key);

            if (memoryValue != null)
            {
                return(memoryValue);
            }

            //If memory cache null, check distributedCache
            T distributedValue = await _distributedCacheManager.GetCacheAsync <T, T2>(key);

            //If values available in distributed cache but not memory cache, update memory cache
            if (distributedValue != null)
            {
                _memoryCachingManager.SetCache(distributedValue, key);
            }

            return(distributedValue);
        }
コード例 #2
0
        /// <summary>
        ///  Set cache in memory and return original object
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="obj"></param>
        public T SetCache <T, T2>(
            T obj,
            T2 key)
        {
            _memoryCachingManager.SetCache(
                obj,
                key);

            _distributedCacheManager.SetCache(
                obj,
                key);

            return(obj);
        }
コード例 #3
0
 private async Task <string> GetResultsFromAPI(string queryString)
 {
     //Use the query string as a key so if query is the same we don't have to make an API call.
     return(_cachingManager.GetCache <string>(queryString) ??
            _cachingManager.SetCache(await client.GetStringAsync(queryString), queryString));
 }