Пример #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(LruCache <ItemType> owner, GetKeyFunc <KeyType, ItemType> getKey, GetValueFunc <KeyType, ItemType> loadItem)
 {
     Debug.Assert(owner != null, "owner argument required");
     Debug.Assert(getKey != null, "GetKey delegate required");
     _owner    = owner;
     _index    = new Dictionary <KeyType, WeakReference>(_owner._capacity * 2);
     _getKey   = getKey;
     _loadItem = loadItem;
     RebuildIndex();
 }
Пример #2
0
            private const int _size = 265; // based on 240 timeslices + 20 bags for ItemLimit + 5 bags empty buffer

            public LifespanMgr(LruCache <ItemType> 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);
            }