Is it there any LRU implementation of IDictionary?

前端 未结 10 1796
走了就别回头了
走了就别回头了 2020-11-29 21:20

I would like to implement a simple in-memory LRU cache system and I was thinking about a solution based on an IDictionary implementation which could handle an hashed LRU mec

10条回答
  •  囚心锁ツ
    2020-11-29 21:32

    I implemented a thread safe pseudo LRU designed for concurrent workloads. Performance is very close to ConcurrentDictionary, ~10x faster than MemoryCache and hit rate is better than a conventional LRU. Full analysis provided in the github link below.

    Usage looks like this:

    int capacity = 666;
    var lru = new ConcurrentLru(capacity);
    
    var value = lru.GetOrAdd(1, (k) => new SomeItem(k));
    

    GitHub: https://github.com/bitfaster/BitFaster.Caching

    Install-Package BitFaster.Caching
    

提交回复
热议问题