Is it there any LRU implementation of IDictionary?

前端 未结 10 1739
走了就别回头了
走了就别回头了 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:42

    There is nothing in the base class libraries that does this.

    On the free side, maybe something like C5's HashedLinkedList would work.

    If you're willing to pay, maybe check out this C# toolkit. It contains an implementation.

    0 讨论(0)
  • 2020-11-29 21:50

    If it's an asp.net app you can use the cache class[1] but you'll be competing for space with other cached stuff, which may be what you want or may not be.

    [1] http://msdn.microsoft.com/en-us/library/system.web.caching.cache.aspx

    0 讨论(0)
  • 2020-11-29 21:51

    Found you answer while googling, also found this:

    http://code.google.com/p/csharp-lru-cache/

    csharp-lru-cache: LRU cache collection class library

    This is a collection class that functions as a least-recently-used cache. It implements ICollection<T>, but also exposes three other members:

    • Capacity, the maximum number of items the cache can contain. Once the collection is at capacity, adding a new item to the cache will cause the least recently used item to be discarded. If the Capacity is set to 0 at construction, the cache will not automatically discard items.
    • Oldest, the oldest (i.e. least recently used) item in the collection.
    • DiscardingOldestItem, an event raised when the cache is about to discard its oldest item. This is an extremely simple implementation. While its Add and Remove methods are thread-safe, it shouldn't be used in heavy multithreading environments because the entire collection is locked during those methods.
    0 讨论(0)
  • 2020-11-29 21:57

    The Caching Application Block of EntLib has an LRU scavenging option out of the box and can be in memory. It might be a bit heavyweight for what you want tho.

    0 讨论(0)
提交回复
热议问题