示例#1
0
        private bool TryLoadAllFromCache()
        {
            if (CurrentRequest.DisableCache)
            {
                return(false);
            }

            // We will try read the response from the cache, but if something happens we will fallback to the normal way.
            try
            {
                //Unless specifically constrained by a cache-control (section 14.9) directive, a caching system MAY always store a successful response (see section 13.8) as a cache entity,
                //  MAY return it without validation if it is fresh, and MAY    return it after successful validation.
                // MAY return it without validation if it is fresh!
                if (HTTPCacheService.IsCachedEntityExpiresInTheFuture(CurrentRequest))
                {
                    CurrentRequest.Response = HTTPCacheService.GetFullResponse(CurrentRequest);

                    if (CurrentRequest.Response != null)
                    {
                        return(true);
                    }
                }
            }
            catch
            {
                HTTPCacheService.DeleteEntity(CurrentRequest.CurrentUri);
            }

            return(false);
        }
示例#2
0
        private bool TryLoadAllFromCache()
        {
            if (CurrentRequest.DisableCache || !HTTPCacheService.IsSupported)
            {
                return(false);
            }

            // We will try read the response from the cache, but if something happens we will fallback to the normal way.
            try
            {
                //Unless specifically constrained by a cache-control (section 14.9) directive, a caching system MAY always store a successful response (see section 13.8) as a cache entity,
                //  MAY return it without validation if it is fresh, and MAY    return it after successful validation.
                // MAY return it without validation if it is fresh!
                if (HTTPCacheService.IsCachedEntityExpiresInTheFuture(CurrentRequest))
                {
                    if (HTTPManager.Logger.Level == Logger.Loglevels.All)
                    {
                        HTTPManager.Logger.Verbose("HTTPConnection", string.Format("{0} - TryLoadAllFromCache - whole response loading from cache", this.CurrentRequest.CurrentUri.ToString()));
                    }

                    CurrentRequest.Response = HTTPCacheService.GetFullResponse(CurrentRequest);

                    if (CurrentRequest.Response != null)
                    {
                        return(true);
                    }
                }
            }
            catch
            {
                HTTPCacheService.DeleteEntity(CurrentRequest.CurrentUri);
            }

            return(false);
        }
        public static bool TryLoadAllFromCache(string context, HTTPRequest request, LoggingContext loggingContext1 = null, LoggingContext loggingContext2 = null, LoggingContext loggingContext3 = null)
        {
            // We will try to read the response from the cache, but if something happens we will fallback to the normal way.
            try
            {
                //Unless specifically constrained by a cache-control (section 14.9) directive, a caching system MAY always store a successful response (see section 13.8) as a cache entity,
                //  MAY return it without validation if it is fresh, and MAY    return it after successful validation.
                // MAY return it without validation if it is fresh!
                if (HTTPManager.Logger.Level == Logger.Loglevels.All)
                {
                    HTTPManager.Logger.Verbose("ConnectionHelper", string.Format("[{0}] - TryLoadAllFromCache - whole response loading from cache", context), loggingContext1, loggingContext2, loggingContext3);
                }

                request.Response = HTTPCacheService.GetFullResponse(request);

                if (request.Response != null)
                {
                    return(true);
                }
            }
            catch
            {
                HTTPManager.Logger.Verbose("ConnectionHelper", string.Format("[{0}] - TryLoadAllFromCache - failed to load content!", context), loggingContext1, loggingContext2, loggingContext3);
                HTTPCacheService.DeleteEntity(request.CurrentUri);
            }

            return(false);
        }
 private bool TryLoadAllFromCache()
 {
     if (!base.CurrentRequest.DisableCache && HTTPCacheService.IsSupported)
     {
         try
         {
             if (HTTPCacheService.IsCachedEntityExpiresInTheFuture(base.CurrentRequest))
             {
                 if (HTTPManager.Logger.Level == Loglevels.All)
                 {
                     HTTPManager.Logger.Verbose("HTTPConnection", $"{base.CurrentRequest.CurrentUri.ToString()} - TryLoadAllFromCache - whole response loading from cache");
                 }
                 base.CurrentRequest.Response = HTTPCacheService.GetFullResponse(base.CurrentRequest);
                 if (base.CurrentRequest.Response != null)
                 {
                     return(true);
                 }
             }
         }
         catch
         {
             HTTPCacheService.DeleteEntity(base.CurrentRequest.CurrentUri, true);
         }
     }
     return(false);
 }
 private bool TryLoadAllFromCache()
 {
     if (CurrentRequest.DisableCache)
     {
         return(false);
     }
     try
     {
         if (HTTPCacheService.IsCachedEntityExpiresInTheFuture(CurrentRequest))
         {
             CurrentRequest.Response = HTTPCacheService.GetFullResponse(CurrentRequest);
             if (CurrentRequest.Response != null)
             {
                 return(true);
             }
         }
     }
     catch
     {
         HTTPCacheService.DeleteEntity(CurrentRequest.CurrentUri);
     }
     return(false);
 }