static void Main(string[] args) { 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()); }
static void Main(string[] args) { 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()); }
public static T Load <T>(string v) where T : class { T Result = myCache.Get <T>(v); if (Result == null) { Result = ContentReaderByType <T> .Load(Path.Combine(ContentDirectory, v)); myCache.Insert(Result, v); } return(Result); }
public static void RunTests() { LRUCache cache = new LRUCache(5); cache.Insert("A", 11); cache.Insert("B", 22); cache.Insert("C", 33); int price = 0; Console.Write(cache.Lookup("A", out price) + " "); Console.WriteLine(price); Console.Write(cache.Lookup("B", out price) + " "); Console.WriteLine(price); Console.Write(cache.Lookup("C", out price) + " "); Console.WriteLine(price); cache.Insert("D", 44); cache.Insert("E", 55); cache.Insert("F", 66); Console.Write(cache.Lookup("F", out price) + " "); Console.WriteLine(price); Console.WriteLine(cache.Lookup("A", out price)); Console.Write(cache.Lookup("B", out price) + " "); Console.WriteLine(price); cache.Remove("F"); Console.WriteLine(cache.Lookup("F", out price)); cache.Update("B", 23); Console.Write(cache.Lookup("B", out price) + " "); Console.WriteLine(price); }
public static void RunTests() { LRUCache cache = new LRUCache(5); cache.Insert("A", 11); cache.Insert("B", 22); cache.Insert("C", 33); int price = 0; Console.Write(cache.Lookup("A", out price) + " "); Console.WriteLine(price); Console.Write(cache.Lookup("B", out price) + " "); Console.WriteLine(price); Console.Write(cache.Lookup("C", out price) + " "); Console.WriteLine(price); cache.Insert("D", 44); cache.Insert("E", 55); cache.Insert("F", 66); Console.Write(cache.Lookup("F", out price) + " "); Console.WriteLine(price); Console.WriteLine(cache.Lookup("A", out price)); Console.Write(cache.Lookup("B", out price) + " "); Console.WriteLine(price); cache.Remove("F"); Console.WriteLine(cache.Lookup("F", out price)); cache.Update("B", 23); Console.Write(cache.Lookup("B", out price) + " "); Console.WriteLine(price); }