Example #1
0
        public void CacheSet(HttpCache cache)
        {
            string    tag = cache.ETag;
            HttpCache ct;

            lock (_CACHE)
            {
                if (_CACHE.TryGetValue(tag, out ct))
                {
                    _cache_curb -= ct.Length;
                    _CACHE[tag]  = cache;
                    _cache_curb += cache.Length;
                }
                else
                {
                    _CACHE.Add(tag, cache);
                    _cache_curb += cache.Length;
                }
            }
            if (_cache_curb > _cache_maxb)
            {
                //delete
                List <HttpCache> rem = new List <HttpCache>();
                foreach (HttpCache cx in _CACHE.Values)
                {
                    rem.Add(cx);
                }
                rem.Sort(HttpCache.SortByDate);

                while (_cache_curb > _cache_maxb)
                {
                    HttpCache c = rem[0];
                    rem.RemoveAt(0);
                    CacheDel(c.ETag);
                }
            }
        }
Example #2
0
 public static int SortByDate(HttpCache a, HttpCache b)
 {
     return(a._date.CompareTo(b._date));
 }