Ejemplo n.º 1
0
 /// <summary>constructor</summary>
 /// <param name="owner">parent of index</param>
 /// <param name="getKey">delegate to get key from object</param>
 /// <param name="loadItem">delegate to load object if it is not found in index</param>
 public Index(LruItemCache <TItem> owner, GetKeyFunc <TKey> getKey, LoadItemFunc <TKey> loadItem)
 {
     _owner    = owner;
     _index    = new Dictionary <TKey, WeakReference>(_owner._capacity * 2);
     _getKey   = getKey;
     _loadItem = loadItem;
     RebuildIndex();
 }
Ejemplo n.º 2
0
            public LifespanMgr(LruItemCache <TItem> owner, TimeSpan minAge, TimeSpan maxAge)
            {
                _owner = owner;
                int maxMS = Math.Min((int)maxAge.TotalMilliseconds, 12 * 60 * 60 * 1000); // max = 12 hours

                _minAge       = minAge;
                _maxAge       = TimeSpan.FromMilliseconds(maxMS);
                _timeSlice    = TimeSpan.FromMilliseconds(maxMS / 240.0); // max timeslice = 3 min
                _bagItemLimit = _owner._capacity / 20;                    // max 5% of capacity per bag
                _bags         = new AgeBag[_size];
                for (int loop = _size - 1; loop >= 0; --loop)
                {
                    _bags[loop] = new AgeBag();
                }
                OpenCurrentBag(DateTime.Now, 0);
            }