Esempio n. 1
0
        internal static Stream PrepareStreamed(Uri uri, HTTPResponse response)
        {
            if (!IsSupported)
            {
                return(null);
            }
            lock (Library)
            {
                if (!Library.TryGetValue(uri, out HTTPCacheFileInfo value))
                {
                    Library.Add(uri, value = new HTTPCacheFileInfo(uri));
                    UsedIndexes.Add(value.MappedNameIDX, value);
                }
                try
                {
                    return(value.GetSaveStream(response));

IL_005b:
                    Stream result;
                    return(result);
                }
                catch
                {
                    DeleteEntity(uri);
                    throw;
IL_006b:
                    Stream result;
                    return(result);
                }
            }
        }
Esempio n. 2
0
        internal static HTTPCacheFileInfo Store(Uri uri, HTTPMethods method, HTTPResponse response)
        {
            if (response == null || response.Data == null || response.Data.Length == 0)
            {
                return(null);
            }
            if (!IsSupported)
            {
                return(null);
            }
            HTTPCacheFileInfo value = null;

            lock (Library)
            {
                if (!Library.TryGetValue(uri, out value))
                {
                    Library.Add(uri, value = new HTTPCacheFileInfo(uri));
                    UsedIndexes.Add(value.MappedNameIDX, value);
                }
                try
                {
                    value.Store(response);
                    return(value);
                }
                catch
                {
                    DeleteEntity(uri);
                    throw;
IL_0087:
                    return(value);
                }
            }
        }
Esempio n. 3
0
 private static void LoadLibrary()
 {
     if (library == null && IsSupported)
     {
         library = new Dictionary <Uri, HTTPCacheFileInfo>();
         if (!File.Exists(LibraryPath))
         {
             DeleteUnusedFiles();
         }
         else
         {
             try
             {
                 int num;
                 lock (library)
                 {
                     using (FileStream input = new FileStream(LibraryPath, FileMode.Open))
                     {
                         using (BinaryReader binaryReader = new BinaryReader(input))
                         {
                             num = binaryReader.ReadInt32();
                             if (num > 1)
                             {
                                 NextNameIDX = binaryReader.ReadUInt64();
                             }
                             int num2 = binaryReader.ReadInt32();
                             for (int i = 0; i < num2; i++)
                             {
                                 Uri uri = new Uri(binaryReader.ReadString());
                                 HTTPCacheFileInfo hTTPCacheFileInfo = new HTTPCacheFileInfo(uri, binaryReader, num);
                                 if (hTTPCacheFileInfo.IsExists())
                                 {
                                     library.Add(uri, hTTPCacheFileInfo);
                                     if (num > 1)
                                     {
                                         UsedIndexes.Add(hTTPCacheFileInfo.MappedNameIDX, hTTPCacheFileInfo);
                                     }
                                 }
                             }
                         }
                     }
                 }
                 if (num == 1)
                 {
                     BeginClear();
                 }
                 else
                 {
                     DeleteUnusedFiles();
                 }
             }
             catch
             {
             }
         }
     }
 }
Esempio n. 4
0
 internal static void SetBodyLength(Uri uri, int bodyLength)
 {
     if (IsSupported)
     {
         lock (Library)
         {
             if (Library.TryGetValue(uri, out HTTPCacheFileInfo value))
             {
                 value.BodyLength = bodyLength;
             }
             else
             {
                 Library.Add(uri, value = new HTTPCacheFileInfo(uri, DateTime.UtcNow, bodyLength));
                 UsedIndexes.Add(value.MappedNameIDX, value);
             }
         }
     }
 }
Esempio n. 5
0
 public static void BeginMaintainence(HTTPCacheMaintananceParams maintananceParam)
 {
     if (maintananceParam == null)
     {
         throw new ArgumentNullException("maintananceParams == null");
     }
     if (IsSupported && !InMaintainenceThread)
     {
         InMaintainenceThread = true;
         SetupCacheFolder();
         new Thread((ParameterizedThreadStart) delegate
         {
             try
             {
                 lock (Library)
                 {
                     DateTime t = DateTime.UtcNow - maintananceParam.DeleteOlder;
                     List <HTTPCacheFileInfo> list = new List <HTTPCacheFileInfo>();
                     foreach (KeyValuePair <Uri, HTTPCacheFileInfo> item in Library)
                     {
                         if (item.Value.LastAccess < t && DeleteEntity(item.Key, removeFromLibrary: false))
                         {
                             list.Add(item.Value);
                         }
                     }
                     for (int i = 0; i < list.Count; i++)
                     {
                         Library.Remove(list[i].Uri);
                         UsedIndexes.Remove(list[i].MappedNameIDX);
                     }
                     list.Clear();
                     ulong num = GetCacheSize();
                     if (num > maintananceParam.MaxCacheSize)
                     {
                         List <HTTPCacheFileInfo> list2 = new List <HTTPCacheFileInfo>(library.Count);
                         foreach (KeyValuePair <Uri, HTTPCacheFileInfo> item2 in library)
                         {
                             list2.Add(item2.Value);
                         }
                         list2.Sort();
                         int num2 = 0;
                         while (num >= maintananceParam.MaxCacheSize && num2 < list2.Count)
                         {
                             try
                             {
                                 HTTPCacheFileInfo hTTPCacheFileInfo = list2[num2];
                                 ulong num3 = (ulong)hTTPCacheFileInfo.BodyLength;
                                 DeleteEntity(hTTPCacheFileInfo.Uri);
                                 num -= num3;
                             }
                             catch
                             {
                             }
                             finally
                             {
                                 num2++;
                             }
                         }
                     }
                 }
             }
             finally
             {
                 SaveLibrary();
                 InMaintainenceThread = false;
             }
         }).Start();
     }
 }