Skip to content

Simple LRUCache implementation in C#. Demo project included for easy and convenient testing. O(1) lookup time, O(1) insertion time, and O(1) deletion time. However, not thread-safe yet, but will be in the future iterations.

License

Notifications You must be signed in to change notification settings

StudyPlay/LRUCache.NET

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

24 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

LRUCache.NET Build Status

O(1) lookup time ~ O(1) insertion time ~ O(1) deletion time

Simple LRUCache implementation in C#. However, not thread-safe yet, but will be in the future iterations

WARNING: It is not not thread-safe yet, but will be in the future iterations so please be cautious of that.

If you would like to use a data structure similar to LRU cache that is thread-safe for the time being then please look into MemoryCache Class.

You can check it out here about how to make the MemoryCache behave like an LRUCache.

Below is a short snippet for a simple usage case:

LRUCache<int, int> lruCache = new LRUCache<int, int>(5);

Console.WriteLine(lruCache.Size());

lruCache.Insert(0, 10);
lruCache.Insert(1, 20);
lruCache.Insert(2, 30);
lruCache.Insert(3, 40);
lruCache.Insert(4, 50);

Console.WriteLine(lruCache.Size());
Console.WriteLine(lruCache.CacheFeed());

lruCache.GetItem(0);
lruCache.GetItem(1);
lruCache.GetItem(2);

Console.WriteLine(lruCache.Size());
Console.WriteLine(lruCache.CacheFeed());

lruCache.Insert(5, 60);
lruCache.Insert(6, 70);
lruCache.Insert(7, 80);
lruCache.Insert(8, 90);
lruCache.Insert(9, 100);

Console.WriteLine(lruCache.Size());
Console.WriteLine(lruCache.CacheFeed());

About

Simple LRUCache implementation in C#. Demo project included for easy and convenient testing. O(1) lookup time, O(1) insertion time, and O(1) deletion time. However, not thread-safe yet, but will be in the future iterations.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C# 100.0%