コード例 #1
0
        public IEnumerable<CacheItem> Load()
        {
            CacheItem[] list = new CacheItem[0]; 

            if (File.Exists(CacheConfig.DBFile))
            {
                try
                {
                    using (FileStream fs = new FileStream(CacheConfig.DBFile, FileMode.Open))
                    {
                        BinaryFormatter formatter = new BinaryFormatter();
                        formatter.Binder = new InsideCOMBinder();

                        object obj = formatter.Deserialize(fs);
                        cache = obj as Dictionary<string, CacheItem>;
                        if (cache == null) cache = new Dictionary<string, CacheItem>();
                        list = cache.Values.ToArray();
                    }
                }
                catch (Exception ex)
                {
                    Debug.WriteLine(ex);
                }
            }

            return list;

            //List<CacheItem> list = new List<CacheItem>();
            //int count = (int)db.Count();
            //for (int i = 0; i < count; i++)
            //{
            //    string val = db.FetchRecordString(i);
            //    CacheItem c = JsonConvert.DeserializeObject<CacheItem>(val);
            //    cache[c.Url] = c;
            //    list.Add(c);
            //}
            //return list;
        }
コード例 #2
0
 /// <summary>
 /// Update item
 /// </summary>
 /// <param name="cacheOld"></param>
 /// <param name="cacheNew"></param>
 public void OnUpdateCacheItemAction(CacheItem cacheOld, CacheItem cacheNew)
 {
     if (View.CacheIndex.ContainsKey(cacheOld.Host))
     {
         CacheHost host = View.CacheIndex[cacheOld.Host];
         if (host.Items.ContainsKey(cacheOld.Url))
         {
             host.Items[cacheOld.Url] = cacheNew;
         }
     }
 }
コード例 #3
0
 public bool DeleteCache(CacheItem item, bool saveIndex)
 {
     cache.Remove(item.Url);
     File.Delete(item.Local);
     if (saveIndex)
     {
         SaveIndex();
     }
     return true;
 }
コード例 #4
0
        public List<CacheItem> AddCache(IEnumerable<Session> oSessions, UpdateCacheItemDelegate updateDelegate)
        {
            List<CacheItem> list = new List<CacheItem>();
            foreach (var session in oSessions)
            {
                CacheItem item = new CacheItem(session, CacheConfig.CacheDir);
                //if (!cacheIndex.ContainsKey(item.Host))
                //{
                //    cacheIndex[item.Host] = new CacheHost();
                //}
                //cacheIndex[item.Host].Items[item.Url] = item;

                if (cache.ContainsKey(item.Url))
                {
                    if (updateDelegate != null)
                    {   
                        updateDelegate(cache[item.Url], item);
                    }
                }
                else
                {
                    list.Add(item);
                }
                cache[item.Url] = item;
                //AddCache(item);
                
            }
            SaveIndex();
            return list;
        }