Exemplo n.º 1
0
        internal static HTTPCacheFileInfo Store(Uri uri, HTTPMethods method, HTTPResponse response)
        {
            if (response == null || response.Data == null || response.Data.Length == 0)
            {
                return(null);
            }
            HTTPCacheFileInfo hTTPCacheFileInfo     = null;
            Dictionary <Uri, HTTPCacheFileInfo> obj = HTTPCacheService.Library;

            lock (obj)
            {
                if (!HTTPCacheService.Library.TryGetValue(uri, out hTTPCacheFileInfo))
                {
                    HTTPCacheService.Library.Add(uri, hTTPCacheFileInfo = new HTTPCacheFileInfo(uri));
                }
                try
                {
                    hTTPCacheFileInfo.Store(response);
                }
                catch
                {
                    HTTPCacheService.DeleteEntity(uri, true);
                    throw;
                }
            }
            return(hTTPCacheFileInfo);
        }
Exemplo n.º 2
0
 private static void ClearImpl(object param)
 {
     try
     {
         string[] files = Directory.GetFiles(HTTPCacheService.CacheFolder);
         for (int i = 0; i < files.Length; i++)
         {
             try
             {
                 string fileName = Path.GetFileName(files[i]);
                 HTTPCacheService.DeleteEntity(HTTPCacheService.GetUriFromFileName(fileName), true);
             }
             catch
             {
             }
         }
     }
     finally
     {
         HTTPCacheService.SaveLibrary();
         HTTPCacheService.InClearThread = false;
     }
 }
Exemplo n.º 3
0
        internal static Stream PrepareStreamed(Uri uri, HTTPResponse response)
        {
            Dictionary <Uri, HTTPCacheFileInfo> obj = HTTPCacheService.Library;
            Stream saveStream;

            lock (obj)
            {
                HTTPCacheFileInfo hTTPCacheFileInfo;
                if (!HTTPCacheService.Library.TryGetValue(uri, out hTTPCacheFileInfo))
                {
                    HTTPCacheService.Library.Add(uri, hTTPCacheFileInfo = new HTTPCacheFileInfo(uri));
                }
                try
                {
                    saveStream = hTTPCacheFileInfo.GetSaveStream(response);
                }
                catch
                {
                    HTTPCacheService.DeleteEntity(uri, true);
                    throw;
                }
            }
            return(saveStream);
        }
Exemplo n.º 4
0
 public static void BeginMaintainence(HTTPCacheMaintananceParams maintananceParam)
 {
     if (maintananceParam == null)
     {
         throw new ArgumentNullException("maintananceParams == null");
     }
     if (HTTPCacheService.InMaintainenceThread)
     {
         return;
     }
     HTTPCacheService.InMaintainenceThread = true;
     HTTPCacheService.SetupCacheFolder();
     new Thread(delegate(object param)
     {
         try
         {
             Dictionary <Uri, HTTPCacheFileInfo> obj = HTTPCacheService.Library;
             lock (obj)
             {
                 DateTime t      = DateTime.UtcNow - maintananceParam.DeleteOlder;
                 List <Uri> list = new List <Uri>();
                 foreach (KeyValuePair <Uri, HTTPCacheFileInfo> current in HTTPCacheService.Library)
                 {
                     if (current.Value.LastAccess < t && HTTPCacheService.DeleteEntity(current.Key, false))
                     {
                         list.Add(current.Key);
                     }
                 }
                 for (int i = 0; i < list.Count; i++)
                 {
                     HTTPCacheService.Library.Remove(list[i]);
                 }
                 list.Clear();
                 ulong num = HTTPCacheService.GetCacheSize();
                 if (num > maintananceParam.MaxCacheSize)
                 {
                     List <HTTPCacheFileInfo> list2 = new List <HTTPCacheFileInfo>(HTTPCacheService.library.Count);
                     foreach (KeyValuePair <Uri, HTTPCacheFileInfo> current2 in HTTPCacheService.library)
                     {
                         list2.Add(current2.Value);
                     }
                     list2.Sort();
                     int num2 = 0;
                     while (num >= maintananceParam.MaxCacheSize && num2 < list2.Count)
                     {
                         try
                         {
                             HTTPCacheFileInfo hTTPCacheFileInfo = list2[num2];
                             ulong num3 = (ulong)((long)hTTPCacheFileInfo.BodyLength);
                             HTTPCacheService.DeleteEntity(hTTPCacheFileInfo.Uri, true);
                             num -= num3;
                         }
                         catch
                         {
                         }
                         finally
                         {
                             num2++;
                         }
                     }
                 }
             }
         }
         finally
         {
             HTTPCacheService.SaveLibrary();
             HTTPCacheService.InMaintainenceThread = false;
         }
     }).Start();
 }