/// <summary> /// Constructs an LRUCache with the given maximum size, maximum age, and expiration interval. /// </summary> /// <param name="capacity"></param> /// <param name="useSizing">Whether or not to use explicit object byte sizes.</param> /// <param name="minSize">Minimum size in bytes in the cache. Below this level and no aging is performed.</param> /// <param name="maxAge">The maximum age in milliseconds an an entry should live in cache /// before it's a candidate to be removed.</param> public LRUCache(int capacity, bool useSizing = false, int minSize = 0, int maxAge = 0) { _storage = new C5.HashedLinkedList <KeyValuePair <K, T> >(new KVPComparer <K, T>()); _capacity = capacity; Size = 0; if (useSizing) { _objectSizes = new Dictionary <K, int>(); } _maxAge = maxAge; RequiredReserve = (minSize <= 0 ? 0 : minSize); _lastAccessedTime = null; if (_maxAge > 0) { _lastAccessedTime = new Dictionary <K, DateTime>(); } }
/// <summary> /// Constructs an LRUCache with the given maximum size, maximum age and expiration interval /// </summary> /// <param name="capacity"></param> /// <param name="useSizing">Whether or not to use explicit object sizes</param> /// <param name="minSize">Minimum size in bytes in the cache. Below this level and no aging is performed.</param> /// <param name="maxAge">The maximum age in milliseconds an an entry should live in cache /// before it's a candidate to be removed.</param> /// <param name="expireInterval">Time in milliseconds between checks for expired entries.</param> public LRUCache(int capacity, bool useSizing = false, int minSize = 0, int maxAge = 0, int expireInterval = 0) { _storage = new C5.HashedLinkedList <KeyValuePair <K, T> >(new KVPComparer <K, T>()); _capacity = capacity; _totalSize = 0; if (useSizing) { _objectSizes = new Dictionary <K, int>(); _useSizing = true; } _maxAge = maxAge; _minSize = (minSize <= 0 ? 0 : minSize); _expireInterval = (expireInterval > 0 ? expireInterval : DEFAULT_EXPIRATION_TIMER_INTERVAL); _lastAccessedTime = null; if (_maxAge > 0) { _lastAccessedTime = new Dictionary <K, DateTime>(); _expireTimer = new Timer(OnTimedEvent, null, _expireInterval, Timeout.Infinite); } }
public void C5_HashedLinkedList() => _ = new C5.HashedLinkedList <Int32>();