/// <summary> /// Makes the specified node the most recently accessed one by moving it to the front of the LRU list. /// </summary> /// <param name="node">The node that was most recently accessed.</param> private void MostRecent(ILruCacheEntry <WeakReference <T>, R> node) { // // NB: We opted for a linked list approach for the LRU cache to have constant overhead for memoized function // invocation, with a minor increment upon cache pruning. Alternatively, we could sort entries by their // last access time, having less overhead during a lookup (just store the new access time) but at the // expensive of having to sort the entries in the Trim procedure. That'd cause a hiccup in lookup times. // // NB: If a ranking based eviction is desirable, resulting in higher lookup speeds but lower pruning speeds, // one can use the CreateEvictedBy* methods on WeakMemoizationCacheFactory. // _lock.EnterWriteLock(); try { while (_lruList.Last != null && !_lruList.Last.Key.TryGetTarget(out _)) { LruLinkedList.RemoveLast(ref _lruList); Interlocked.Decrement(ref _count); } LruLinkedList.MoveFirst(ref _lruList, node); } finally { _lock.ExitWriteLock(); } }
/// <summary> /// Makes the specified node the most recently accessed one by moving it to the front of the LRU list. /// </summary> /// <param name="node">The node that was most recently accessed.</param> private void MostRecent(ILruCacheEntry <T, R> node) { // // NB: We opted for a linked list approach for the LRU cache to have constant overhead for memoized function // invocation, with a minor increment upon cache pruning. Alternatively, we could sort entries by their // last access time, having less overhead during a lookup (just store the new access time) but at the // expense of having to sort the entries in the Trim procedure. That'd cause a hiccup in lookup times. // // NB: If a ranking based eviction is desirable, resulting in higher lookup speeds but lower pruning speeds, // one can use the CreateEvictedBy* methods on MemoizationCacheFactory. // LruLinkedList.MoveFirst(ref _lruList, node); }