Class LRUCache<TKey, TValue>
A generic, thread-unsafe Least Recently Used (LRU) cache. Provides O(1) for Get, Set, and Remove operations.
Inheritance
object
LRUCache<TKey, TValue>
Namespace: Global
Assembly: Dew.Core.dll
Syntax
public class LRUCache<TKey, TValue>
Type Parameters
| Name | Description |
|---|---|
| TKey | The type of the key. |
| TValue | The type of the value. |
Constructors
LRUCache(int)
Declaration
public LRUCache(int capacity)
Parameters
| Type | Name | Description |
|---|---|---|
| int | capacity |
Properties
Count
Declaration
public int Count { get; }
Property Value
| Type | Description |
|---|---|
| int |
Methods
Clear()
Declaration
public void Clear()
Set(TKey, TValue)
Adds or updates a key/value pair. If added, it becomes the most recently used. If the cache is at capacity, the least recently used item is removed.
Declaration
public void Set(TKey key, TValue value)
Parameters
| Type | Name | Description |
|---|---|---|
| TKey | key | |
| TValue | value |
TryGet(TKey, out TValue)
Tries to get a value from the cache. If found, it's marked as most recently used.
Declaration
public bool TryGet(TKey key, out TValue value)
Parameters
| Type | Name | Description |
|---|---|---|
| TKey | key | |
| TValue | value |
Returns
| Type | Description |
|---|---|
| bool |