コード例 #1
0
ファイル: Program.cs プロジェクト: mohsenShakiba/LRUCache
        static void Main(string[] args)
        {
            var options = new LRUCacheOptions(1000);

            //options.DataPersist = new FileBasedCacheStore("test.bin");
            cache = new LRUCache.LRUCache(options);

            var list = new List <Thread>();

            var sw = new Stopwatch();

            sw.Start();

            for (int i = 0; i < 10; i++)
            {
                var t = new Thread(BenchMarkTest);
                t.Start();

                list.Add(t);
            }

            foreach (var t in list)
            {
                t.Join();
            }

            sw.Stop();

            Console.WriteLine("ended in {0}", sw.ElapsedMilliseconds);

            Console.ReadLine();
        }
コード例 #2
0
        public void ItemGet_ExpiredItemMustBeRemoved()
        {
            var options = new LRUCacheOptions();
            var store   = new LRUCacheStore(options);

            var entry = CacheEntry.New("key", "value", TimeSpan.FromMilliseconds(500));

            store.AddEntry(entry);

            Thread.Sleep(1000);

            Assert.Null(store.GetEntry("key"));
        }
コード例 #3
0
        public void ItemGet_ExpiryMustBeUpdated()
        {
            var options = new LRUCacheOptions();
            var store   = new LRUCacheStore(options);

            var entry = CacheEntry.New("key", "value", TimeSpan.FromMilliseconds(1500));

            store.AddEntry(entry);

            Thread.Sleep(1000);

            // entry must be updated to last another 1500 milliseconds
            Assert.NotNull(store.GetEntry("key"));

            Thread.Sleep(1000);

            // updated entry must still exist
            Assert.NotNull(store.GetEntry("key"));
        }