Пример #1
0
        /// <summary>
        /// Used to retrieve a class that inherits from CacheIndex
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="requestUrl"></param>
        /// <param name="collectionIdentifier"></param>
        /// <returns>First it tries to get a index from memoryCache, then from fileCache and after that returns null, if no index is found</returns>
        public static async Task <T> retrieve <T>(string requestUrl, IonConfig config) where T : CacheIndex
        {
            T index = MemoryCacheIndex.get <T>(requestUrl, config.collectionIdentifier);

            if (index != null)
            {
                IonLogging.log("Index lookup " + requestUrl + " from memory", IonLogMessageTypes.SUCCESS);
                return(index);
            }

            // check isolated storage
            try
            {
                index = await StorageUtils.getIndexAsync <T>(requestUrl, config).ConfigureAwait(false);

                if (index != null)
                {
                    IonLogging.log("Index lookup " + requestUrl + " from isolated storage", IonLogMessageTypes.SUCCESS);
                }
            }
            catch (Exception e)
            {
                IonLogging.log("Index lookup " + requestUrl + " is not in isolated storage. Message: " + e.Message, IonLogMessageTypes.INFORMATION);
            }

            // Save to memory cache, if index is not null
            if (index != null)
            {
                MemoryCacheIndex.put(requestUrl, config.collectionIdentifier, index);
            }

            return(index);
        }
Пример #2
0
        /// <summary>
        /// Saves a index to memory and isolated storage cache
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="requestURL"></param>
        /// <param name="cacheIndex"></param>
        /// <param name="config"></param>
        public static async Task save <T>(string requestURL, T cacheIndex, IonConfig config) where T : CacheIndex
        {
            try
            {
                // save to memory cache
                MemoryCacheIndex.put <T>(requestURL, config.collectionIdentifier, cacheIndex);

                // save to isolated storage
                await StorageUtils.saveIndexAsync(requestURL, cacheIndex, config).ConfigureAwait(false);
            }
            catch (Exception e)
            {
                IonLogging.log("Cache Index " + requestURL + " could not be saved. Message: " + e.Message, IonLogMessageTypes.ERROR);
            }
        }