Esempio n. 1
0
        /// <summary>
        /// Gets the resource response.
        /// </summary>
        /// <param name="uri">The URI of the request.</param>
        /// <param name="args">The arguments to be used on the request.</param>
        /// <returns></returns>
        public override ResourceResponse GetResponse(string uri, NetworkResourceArguments args)
        {
            ResourceResponseCache response = new ResourceResponseCache(uri, args);

            // find the item in the cache index
            CacheIndex     cacheIndex     = CacheIndexMap.GetFromUri(uri);
            CacheIndexItem cacheIndexItem = cacheIndex.Get(uri);

            // ensure cache item is current
            response.ReturnStatus = cacheIndex.EnsureCurrentCache(cacheIndexItem, args);

            // store local references to cache index and item to prevent having to look up
            // values again later.
            response.CacheIndex     = cacheIndex;
            response.CacheIndexItem = cacheIndexItem;

            // populate response data collection with cache index values;
            response.Data.Add("RelativeUri", cacheIndexItem.RelativeUri);
            response.Data.Add("AttemptToRefresh", cacheIndexItem.AttemptToRefresh.ToString());
            response.Data.Add("Downloaded", cacheIndexItem.Downloaded.ToString());
            response.Data.Add("Expiration", cacheIndexItem.Expiration.ToString());
            response.Data.Add("IsExpired", cacheIndexItem.IsExpired.ToString());
            response.Data.Add("IsStale", cacheIndexItem.IsStale.ToString());
            response.Data.Add("ETag", cacheIndexItem.ETag);

            return(response);
        }
Esempio n. 2
0
        /// <summary>
        /// method to initiate Prefetch processing based on provided manifest uri.
        /// </summary>
        /// <param name="manifestUri"></param>
        public static void InitiatePrefetch(string manifestUri)
        {
            // if cache is not supported then don't bother prefetching.
            if (Device.NetworkGetMethod == MonoCross.Utilities.Network.NetworkGetMethod.NoCache)
            {
                Device.Log.Debug("Cache is not supported, prefetch request ignored.");
                return;
            }

            CacheManifest cacheManifest = CacheManifest.CreateFromUri(manifestUri);

            CacheIndexMap.Add(cacheManifest);
            Device.Thread.QueueIdle(CacheIndexMap.PreFetchIndexes);
            Device.Thread.QueueIdle(CacheIndexMap.CleanIndexes);
        }