protected override void OnRegister()
        {
            if (Parent.IsActive)
            {
                GameEvents.Modifiers.OnCurrencyModifierQuery.Add(new EventData <CurrencyModifierQuery> .OnEvent(OnEffectQuery));
                GameEvents.Contract.onDeclined.Add(new EventData <Contract> .OnEvent(OnContractChange));
                GameEvents.Contract.onOffered.Add(new EventData <Contract> .OnEvent(OnContractChange));

                if (!initialSetupDone)
                {
                    initialSetupDone = true;
                    Debug.Log("Contract Slot Machine: initial setup");

                    // Initialize the value cache to all zeros
                    OnContractChange(null);
                    ConfigNode node = new ConfigNode();
                    valueCache.Save(node);

                    foreach (ConfigNode.Value pair in node.values)
                    {
                        pair.value = "1.0";
                    }
                    valueCache.Clear();
                    valueCache.Load(node);
                }
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Closes this layer.
        /// </summary>
        public override void Close()
        {
            base.Close();

            try
            {
                if (_timer != null)
                {
                    _timer.Change(System.Threading.Timeout.Infinite, System.Threading.Timeout.Infinite);
                    _timer.Dispose();
                    _timer = null;
                }

                lock (_cache)
                {
                    _cache.OnRemove = null;
                    _cache.Clear();
                }
                _cache = null;

                lock (_stack)
                { // make sure the tile range is not in use.
                    _stack.Clear();
                }
                _stack = null;

                // flushes all images from the cache.
                _nativeImageCache.Flush();
            }
            catch (Exception ex)
            { // don't worry about exceptions here.
                OsmSharp.Logging.Log.TraceEvent("LayerTile", Logging.TraceEventType.Error, ex.Message);
            }
        }
        public async Task ClearAsync(
            CancellationToken ct = default)
        {
            await inner.ClearAsync(ct);

            cache.Clear();
        }
Ejemplo n.º 4
0
        public void Tests()
        {
            var cache = new LRUCache <int, int>(3);

            Assert.AreEqual(0, cache.Count);
            cache.Set(1, 10);
            Assert.AreEqual(1, cache.Count);
            cache.Set(2, 20);
            Assert.AreEqual(2, cache.Count);
            cache.Set(3, 30);
            Assert.AreEqual(3, cache.Count);
            Assert.AreEqual(10, cache[1]);
            Assert.AreEqual(20, cache[2]);
            Assert.AreEqual(30, cache[3]);

            cache.Set(4, 40);
            Assert.IsFalse(cache.ContainsKey(1));
            Assert.AreEqual(40, cache[4]);
            Assert.AreEqual(3, cache.Count);

            cache[4] = 400;
            Assert.AreEqual(400, cache[4]);

            cache[2] = 200;
            Assert.AreEqual(200, cache[2]);
            cache[3] = 300;
            Assert.AreEqual(300, cache[3]);

            cache.Set(1, 10);
            Assert.IsFalse(cache.ContainsKey(4));

            cache.Clear();
            Assert.AreEqual(0, cache.Count);
            Assert.IsFalse(cache.ContainsKey(1));
        }
        public void PerformPutOrGetAndClear()
        {
            try
            {
                Console.WriteLine(string.Format("Starting thread #{0} ", this.taskIndex));
                foreach (String line in userAgents)
                {
                    try
                    {
                        cache.GetEntry(line);
                        if (taskIndex % 2 == 0 && readLines % 300 == 0)
                        {
                            cache.Clear();
                        }
                        else if (taskIndex % 2 != 0)
                        {
                            cache.PutEntry(line, new object());
                        }

                        readLines++;
                    }
                    catch (Exception e)
                    {
                        Assert.Fail("Test failed with exceptions " + e.StackTrace);
                    }
                }
                this.success = true;
            }
            finally
            {
                Console.WriteLine(string.Format("{0} user agents read", readLines));
                Console.WriteLine(string.Format("Thread #{0} finished execution", this.taskIndex));
            }
        }
Ejemplo n.º 6
0
        public Task Init()
        {
            return(Task.Run(() =>
            {
                try
                {
                    imagesCache.Clear();
                    imagesSizeCache.Clear();
                    thumbnailsCache.Clear();
                    var files = thumbnailCacheDirectory.GetFiles("*.*", SearchOption.AllDirectories);
                    files.Where(file => file.CreationTime < DateTime.Now.AddDays(-14)).ToList().ForEach(file => file.Delete());
                    var directories = thumbnailCacheDirectory.GetDirectories();
                    foreach (var dir in directories)
                    {
                        var archives = dir.GetDirectories();
                        archives.Where(dir => dir.GetFiles().Length == 0).ToList().ForEach(dir => dir.Delete());
                    }
                    directories.Where(dir => dir.GetDirectories().Length == 0).ToList().ForEach(dir => dir.Delete());
                }
                catch (Exception e)
                {
#if WINDOWS_UWP
                    Crashes.TrackError(e);
#endif
                }
            }));
        }
Ejemplo n.º 7
0
        public void LRUCache_Basic()
        {
            LRUCache <string, string> cache;
            string value;

            cache = new LRUCache <string, string>(StringComparer.OrdinalIgnoreCase);
            Assert.AreEqual(0, cache.Count);

            cache.Add("foo", "bar");
            Assert.AreEqual(1, cache.Count);
            Assert.AreEqual("bar", cache["foo"]);

            try
            {
                value = cache["xxx"];
                Assert.Fail("Expected a KeyNotFoundException");
            }
            catch (Exception e)
            {
                Assert.AreEqual(typeof(KeyNotFoundException).Name, e.GetType().Name);
            }

            cache["foo"] = "foobar";
            Assert.AreEqual("foobar", cache["foo"]);

            cache["bar"] = "boobar";
            Assert.AreEqual("boobar", cache["bar"]);
            Assert.AreEqual("foobar", cache["foo"]);

            Assert.IsTrue(cache.TryGetValue("foo", out value));
            Assert.AreEqual("foobar", value);
            Assert.IsTrue(cache.TryGetValue("bar", out value));
            Assert.AreEqual("boobar", value);
            Assert.IsFalse(cache.TryGetValue("xxx", out value));

            Assert.IsTrue(cache.ContainsKey("foo"));
            Assert.IsTrue(cache.ContainsKey("bar"));
            Assert.IsFalse(cache.ContainsKey("xxx"));

            cache.Remove("foo");
            Assert.IsFalse(cache.ContainsKey("foo"));

            cache.Remove("bar");
            Assert.IsFalse(cache.ContainsKey("bar"));

            cache.Remove("xxx");
            Assert.IsFalse(cache.ContainsKey("xxx"));

            cache["foo"] = "foobar";
            cache["bar"] = "boobar";
            Assert.AreEqual(2, cache.Count);
            Assert.IsTrue(cache.ContainsKey("foo"));
            Assert.IsTrue(cache.ContainsKey("bar"));
            cache.Clear();
            Assert.AreEqual(0, cache.Count);
            Assert.IsFalse(cache.ContainsKey("foo"));
            Assert.IsFalse(cache.ContainsKey("bar"));
        }
Ejemplo n.º 8
0
        public static void Unload()
        {
            Subtitle.Dispose();
            Title.Dispose();
            Splash.Dispose();
            MapSheet.Dispose();
            MiniHP.Dispose();
            HPMenu.Dispose();
            Buttons.Dispose();
            Shadows.Dispose();
            Darkness.Dispose();
            BattleFactors.Dispose();
            Strip.Dispose();
            Cursor.Dispose();
            Arrows.Dispose();
            PicBorder.Dispose();
            MenuBorder.Dispose();
            MenuBG.Dispose();

            tileCache.Clear();
            objectCache.Clear();
            bgCache.Clear();
            itemCache.Clear();
            iconCache.Clear();
            vfxCache.Clear();
            portraitCache.Clear();
            spriteCache.Clear();

            DivTex.Dispose();

            EXPFont.Dispose();
            HealFont.Dispose();
            DamageFont.Dispose();
            DungeonFont.Dispose();
            TextFont.Dispose();

            SysFont.Dispose();

            Pixel.Dispose();
            defaultTex.Dispose();

            Loaded = false;
            //Notify script engine
            LuaEngine.Instance.OnGraphicsUnload();
        }
Ejemplo n.º 9
0
        public void TestClear()
        {
            LRUCache <String, String> underTest = new LRUCache <String, String>(666);

            underTest.Add("key1", "value");
            underTest.Add("key2", "value");
            underTest.Add("key3", "value");
            Assert.That(underTest.Count == 3);
            underTest.Clear();
            Assert.That(underTest.Count == 0);
        }
Ejemplo n.º 10
0
        public static void Exit()
        {
            Picker.Dispose();
            MenuBack.Dispose();

            tileCache.Clear();
            objectCache.Clear();
            itemCache.Clear();
            statusCache.Clear();
            spellCache.Clear();
            mugshotCache.Clear();
            spriteCache.Clear();

            BlankTexture.Dispose();
            ErrorTexture.Dispose();

            SingleFont.Dispose();

            TextureProgram.Dispose();
        }
Ejemplo n.º 11
0
        /// <summary>
        /// Disposes of all native resource associated with this array.
        /// </summary>
        public sealed override void Dispose()
        {
            // clear cache.
            _cachedBuffers.Clear();

            // dispose only the accessors, the file may still be in use.
            foreach (var accessor in _accessors)
            {
                accessor.Dispose();
            }
        }
Ejemplo n.º 12
0
        public void Clean(bool hard = true)
        {
            Gallery.Children.Clear();
            ImgCache.Clear();

            ImgFull.Source    = null;
            ImgFull.IsEnabled = false;

            VideoFull.Close();

            currentBtn = null;
        }
Ejemplo n.º 13
0
        public void TestClear()
        {
            LRUCache <string, string> cache = new LRUCache <string, string>(100);

            for (int i = 0; i < 100; i++)
            {
                cache.Put(i.ToString(), i.ToString());
            }

            cache.Clear();

            Assert.AreEqual(cache.Size, 0);
        }
Ejemplo n.º 14
0
    public void Save()
    {
        mapLoaded = false;
        gridMap.Save();
        entityPropertyManager.Save();
        chunkCache.Clear();
        player.GetComponent <XCharacterController>().Save();

        string mapDataJson = JsonUtility.ToJson(mapData);

        using (StreamWriter writer = new StreamWriter(new FileStream(MapDir + "/map.json", FileMode.Create, FileAccess.Write)))
        {
            writer.Write(mapDataJson);
        }
    }
Ejemplo n.º 15
0
        /// <summary>
        /// Closes this layer.
        /// </summary>
        public override void Close()
        {
            base.Close();

            lock (_cache)
            {
                _cache.OnRemove = null;
                _cache.Clear();
            }
            _cache = null;

            // flushes all images from the cache.
            _nativeImageCache.Flush();

            // closes the connection.
            _connection.Close();
        }
Ejemplo n.º 16
0
        public void Clear()
        {
            var dico = new LRUCache<string, int>();

            dico.Set("one", 1);
            dico.Set("two", 2);
            dico.Set("three", 3);
            Assert.AreEqual(1, dico.RawGet("one"));
            Assert.AreEqual(2, dico.RawGet("two"));
            Assert.AreEqual(3, dico.RawGet("three"));
            Assert.AreEqual(3, dico.Count);
            Assert.AreEqual(3, dico.NbUpdate);

            dico.Clear();
            Assert.AreEqual(0, dico.RawGet("one"));
            Assert.AreEqual(0, dico.RawGet("two"));
            Assert.AreEqual(0, dico.RawGet("three"));
            Assert.AreEqual(0, dico.Count);
        }
Ejemplo n.º 17
0
        public void LRUCache_Clear_Test()
        {
            // Arrange
            var capacity = 5;
            var cache    = new LRUCache <int, string>(capacity);

            // Act
            AddItems(cache, capacity);
            cache.Clear();

            // Assert
            for (var i = 0; i < capacity; i++)
            {
                var result = cache.TryGetValue(i, out var retrievedValue);
                Assert.IsFalse(result, "Get operation should be unsuccessful.");
                Assert.Null(retrievedValue, "Retrieved value should be null after clearing cache.");
            }

            Assert.AreEqual(0, cache.Count, "Cache should be empty.");
        }
Ejemplo n.º 18
0
 public void InvalidateCache()
 {
     Cache.Clear();
 }
Ejemplo n.º 19
0
 private void OnGameSceneLoadRequested(GameScenes scene)
 {
     contractCache.Clear();
     cachedVessel = null;
 }
Ejemplo n.º 20
0
        static void LRUCacheTest()
        {
            try
            {
                bool   runForever = true;
                int    capacity   = 2048;
                int    evictCount = 512;
                int    loadCount  = 256;
                bool   cacheDebug = true;
                int    dataLen    = 4096;
                byte[] data       = InitByteArray(dataLen, 0x00);
                byte[] keyData;

                LRUCache <string, byte[]> cache = new LRUCache <string, byte[]>(capacity, evictCount, cacheDebug);
                Thread.Sleep(250);

                while (runForever)
                {
                    Console.WriteLine("-------------------------------------------------------------------------------");
                    Console.WriteLine("Available commands (LRU Cache Test):");
                    Console.WriteLine("  get              Get entry by key");
                    Console.WriteLine("  load             Load " + loadCount + " new records");
                    Console.WriteLine("  last_used        Get the last used entry");
                    Console.WriteLine("  first_used       Get the first used entry");
                    Console.WriteLine("  oldest           Get the oldest entry");
                    Console.WriteLine("  newest           Get the newest entry");
                    Console.WriteLine("  count            Get the count of cached entries");
                    Console.WriteLine("  clear            Clear the cache");
                    Console.WriteLine("  quit             Exit the application");
                    Console.WriteLine("  debug            Flip the cache debug flag (currently " + cache.Debug + ")");

                    Console.WriteLine("");
                    Console.Write("Command > ");
                    string userInput = Console.ReadLine();
                    if (String.IsNullOrEmpty(userInput))
                    {
                        continue;
                    }

                    switch (userInput.ToLower())
                    {
                    case "get":
                        Console.Write("Key > ");
                        string getKey = Console.ReadLine();
                        if (String.IsNullOrEmpty(getKey))
                        {
                            break;
                        }
                        if (cache.TryGet(getKey, out keyData))
                        {
                            Console.WriteLine("Cache hit");
                        }
                        else
                        {
                            Console.WriteLine("Cache miss");
                        }
                        break;

                    case "load":
                        DateTime startTime = DateTime.Now;

                        for (int i = 0; i < loadCount; i++)
                        {
                            string loadKey = Guid.NewGuid().ToString();
                            Console.Write("Adding entry " + i + " of " + loadCount + "                      \r");
                            cache.AddReplace(loadKey, data);
                        }

                        Console.WriteLine(
                            "Loaded " + loadCount +
                            " records in " + TotalTimeFrom(startTime) + ": " +
                            DecimalToString(TotalMsFrom(startTime) / loadCount) + "ms per entry");
                        break;

                    case "last_used":
                        Console.WriteLine("Last used key: " + cache.LastUsed());
                        break;

                    case "first_used":
                        Console.WriteLine("First used key: " + cache.FirstUsed());
                        break;

                    case "oldest":
                        Console.WriteLine("Oldest key: " + cache.Oldest());
                        break;

                    case "newest":
                        Console.WriteLine("Newest key: " + cache.Newest());
                        break;

                    case "count":
                        Console.WriteLine("Cache count: " + cache.Count());
                        break;

                    case "clear":
                        cache.Clear();
                        Console.WriteLine("Cache cleared");
                        break;

                    case "q":
                    case "quit":
                        runForever = false;
                        break;

                    case "debug":
                        cache.Debug = !cache.Debug;
                        break;

                    default:
                        continue;
                    }
                }

                Console.WriteLine("Goodbye!");
                return;
            }
            catch (Exception e)
            {
                PrintException(e);
            }
            finally
            {
                Console.WriteLine("");
                Console.Write("Press ENTER to exit.");
                Console.ReadLine();
            }
        }
Ejemplo n.º 21
0
        public void TestLRUCache()
        {
            var cache = new LRUCache<string, int>(3); // make a tiny cache of three elements

            Assert.IsTrue(cache.Capacity == 3 && cache.Count == 0);

            // add three elements

            Assert.IsFalse(cache.ContainsKey("one"));
            Assert.IsTrue(cache.Get("one") == 0);
            cache.Add("one", 1);
            Assert.IsTrue(cache.ContainsKeyAt("one", 0));
            Assert.IsTrue(cache.Get("one") == 1);
            Assert.IsTrue(cache.Count == 1);

            Assert.IsFalse(cache.ContainsKey("two"));
            Assert.IsTrue(cache.Get("two") == 0);
            cache.Add("two", 2);
            Assert.IsTrue(cache.ContainsKeyAt("two", 1));
            Assert.IsTrue(cache.Get("two") == 2);
            Assert.IsTrue(cache.Count == 2);

            Assert.IsFalse(cache.ContainsKey("three"));
            Assert.IsTrue(cache.Get("three") == 0);
            cache.Add("three", 3);
            Assert.IsTrue(cache.ContainsKeyAt("three", 2));
            Assert.IsTrue(cache.Get("three") == 3);
            Assert.IsTrue(cache.Count == 3);

            // we're at capacity. if we add another element,
            // "one" will get evicted since it's least recently used

            Assert.IsTrue(cache.Count == cache.Capacity);

            cache.Add("four", 4);
            Assert.IsTrue(cache.Get("four") == 4);

            Assert.IsTrue(cache.Count == 3);
            Assert.IsTrue(cache.ContainsKeyAt("four", 2));  // from the youngest
            Assert.IsTrue(cache.ContainsKeyAt("three", 1)); // ...
            Assert.IsTrue(cache.ContainsKeyAt("two", 0));   // to the oldest
            Assert.IsFalse(cache.ContainsKey("one"));

            // now let's touch "two" because that's the least recently used one.
            // by doing that, we demote "three" to be the least recently used one,
            // and adding a new entry will then evict it.

            Assert.IsTrue(cache.Get("two") == 2); // reading the key will touch it
            Assert.IsTrue(cache.ContainsKeyAt("two", 2));   // now two is the youngest
            Assert.IsTrue(cache.ContainsKeyAt("four", 1));  // ...
            Assert.IsTrue(cache.ContainsKeyAt("three", 0)); // and three is the oldest

            Assert.IsTrue(cache.Count == cache.Capacity);

            cache.Add("five", 5);
            Assert.IsTrue(cache.Get("five") == 5);

            Assert.IsTrue(cache.Count == 3);
            Assert.IsTrue(cache.ContainsKeyAt("five", 2)); // youngest
            Assert.IsTrue(cache.ContainsKeyAt("two", 1));  // ...
            Assert.IsTrue(cache.ContainsKeyAt("four", 0)); // oldest
            Assert.IsFalse(cache.ContainsKey("three")); // evicted as lru

            // finally we remove one item, dropping the count.
            // adding another item will not cause evictions

            Assert.IsTrue(cache.Remove("four"));
            Assert.IsFalse(cache.ContainsKey("four"));
            Assert.IsTrue(cache.Get("four") == 0);

            Assert.IsTrue(cache.Count == cache.Capacity - 1);

            cache.Add("six", 6);
            Assert.IsTrue(cache.Get("six") == 6);

            Assert.IsTrue(cache.Count == 3);
            Assert.IsTrue(cache.ContainsKeyAt("six", 2));  // youngest
            Assert.IsTrue(cache.ContainsKeyAt("five", 1)); // ...
            Assert.IsTrue(cache.ContainsKeyAt("two", 0));  // oldest
            Assert.IsFalse(cache.ContainsKey("four"));   // removed manually

            // test clearing

            cache.Clear();
            Assert.IsTrue(cache.Count == 0);
        }
 public void Dispose()
 {
     m_Disposed = true;
     m_Cache.Clear();
 }
Ejemplo n.º 23
0
        public void LRUCache_AutoDispose()
        {
            LRUCache <int, TestItem> cache;
            DisposableItem           dItem0 = new DisposableItem(0);
            DisposableItem           dItem1 = new DisposableItem(1);
            DisposableItem           dItem2 = new DisposableItem(2);
            TestItem item0 = new TestItem(0);
            TestItem item1 = new TestItem(1);
            TestItem item2 = new TestItem(2);

            cache             = new LRUCache <int, TestItem>();
            cache.AutoDispose = true;

            // Verify that disposable items are disposed when they
            // are implicitly removed from the cache when the maximum
            // number of items allowed has been exceeded.

            cache.MaxItems = 2;
            cache.Add(0, dItem0);
            cache.Add(1, dItem1);
            cache.Add(2, dItem2);

            Assert.AreEqual(2, cache.Count);
            Assert.IsTrue(dItem0.IsDisposed);
            Assert.IsFalse(dItem1.IsDisposed);
            Assert.IsFalse(dItem2.IsDisposed);

            // Verify that disposable items are disposed when the
            // cache is cleared.

            cache.Clear();
            Assert.IsTrue(dItem1.IsDisposed);
            Assert.IsTrue(dItem2.IsDisposed);

            // Verify that disposable items are disposed when they
            // are explicitly removed.

            dItem0.IsDisposed = false;
            cache.Add(0, dItem0);
            cache.Remove(0);
            Assert.IsTrue(dItem0.IsDisposed);

            // Verify that disposable items are disposed when they
            // are replaced in the cache.

            cache.Clear();
            dItem0.IsDisposed = false;
            dItem1.IsDisposed = false;
            cache.Add(0, dItem0);
            cache[0] = dItem1;
            Assert.IsTrue(dItem0.IsDisposed);

            // Verify that replacing the same disposable item instance
            // doesn't dispose the object.

            cache.Clear();
            dItem0.IsDisposed = false;
            cache.Add(0, dItem0);
            cache[0] = dItem0;
            Assert.IsFalse(dItem0.IsDisposed);

            // Verify that non-disposable items don't cause trouble
            // when AutoDispose=true

            cache.Clear();
            cache.Add(0, item0);
            cache.Add(1, item1);
            cache.Add(2, item2);
            cache.Remove(1);
            cache[1] = new TestItem(3);
            cache[2] = cache[2];
            cache.Clear();
        }
Ejemplo n.º 24
0
        public void LRUCache_MaxItems()
        {
            LRUCache <int, int> cache;
            int value;

            cache = new LRUCache <int, int>();
            Assert.AreEqual(0, cache.Count);
            Assert.AreEqual(int.MaxValue, cache.MaxItems);
            cache.MaxItems = 3;

            //---------------------------------------------

            cache.Clear();
            for (int i = 0; i < 3; i++)
            {
                cache.Add(i, i);
            }

            Assert.AreEqual(3, cache.Count);
            cache.Add(3, 3);
            Assert.AreEqual(3, cache.Count);

            Assert.IsFalse(cache.ContainsKey(0));
            Assert.IsTrue(cache.ContainsKey(1));
            Assert.IsTrue(cache.ContainsKey(2));
            Assert.IsTrue(cache.ContainsKey(3));

            //---------------------------------------------

            cache.Clear();
            for (int i = 0; i < 3; i++)
            {
                cache[i] = i;
            }

            Assert.AreEqual(3, cache.Count);
            cache[3] = 3;
            Assert.AreEqual(3, cache.Count);

            Assert.IsFalse(cache.ContainsKey(0));
            Assert.IsTrue(cache.ContainsKey(1));
            Assert.IsTrue(cache.ContainsKey(2));
            Assert.IsTrue(cache.ContainsKey(3));

            //---------------------------------------------

            cache.Clear();
            for (int i = 0; i < 3; i++)
            {
                cache[i] = i;
            }

            Assert.AreEqual(3, cache.Count);
            cache.MaxItems = 2;
            Assert.AreEqual(2, cache.Count);

            Assert.IsFalse(cache.ContainsKey(0));
            Assert.IsTrue(cache.ContainsKey(1));
            Assert.IsTrue(cache.ContainsKey(2));

            cache.MaxItems = 3;

            //---------------------------------------------

            cache.Clear();
            for (int i = 0; i < 3; i++)
            {
                cache[i] = i;
            }

            Assert.IsTrue(cache.ContainsKey(0));

            Assert.AreEqual(3, cache.Count);
            cache[3] = 3;
            Assert.AreEqual(3, cache.Count);

            Assert.IsTrue(cache.ContainsKey(0));
            Assert.IsFalse(cache.ContainsKey(1));
            Assert.IsTrue(cache.ContainsKey(2));
            Assert.IsTrue(cache.ContainsKey(3));

            //---------------------------------------------

            cache.Clear();
            for (int i = 0; i < 3; i++)
            {
                cache[i] = i;
            }

            cache.Touch(0);

            Assert.AreEqual(3, cache.Count);
            cache[3] = 3;
            Assert.AreEqual(3, cache.Count);

            Assert.IsTrue(cache.ContainsKey(0));
            Assert.IsFalse(cache.ContainsKey(1));
            Assert.IsTrue(cache.ContainsKey(2));
            Assert.IsTrue(cache.ContainsKey(3));

            //---------------------------------------------

            cache.Clear();
            for (int i = 0; i < 3; i++)
            {
                cache[i] = i;
            }

            cache.TryGetValue(0, out value);

            Assert.AreEqual(3, cache.Count);
            cache[3] = 3;
            Assert.AreEqual(3, cache.Count);

            Assert.IsTrue(cache.ContainsKey(0));
            Assert.IsFalse(cache.ContainsKey(1));
            Assert.IsTrue(cache.ContainsKey(2));
            Assert.IsTrue(cache.ContainsKey(3));

            //---------------------------------------------

            cache.Clear();
            for (int i = 0; i < 6; i++)
            {
                cache[i] = i;
            }

            cache.TryGetValue(0, out value);

            Assert.AreEqual(3, cache.Count);
            cache[3] = 3;
            Assert.AreEqual(3, cache.Count);

            Assert.IsFalse(cache.ContainsKey(0));
            Assert.IsFalse(cache.ContainsKey(1));
            Assert.IsFalse(cache.ContainsKey(2));
            Assert.IsTrue(cache.ContainsKey(3));
            Assert.IsTrue(cache.ContainsKey(4));
            Assert.IsTrue(cache.ContainsKey(5));
        }
Ejemplo n.º 25
0
 public static void ClearCaches()
 {
     tileCache.Clear();
     tilesetCache.Clear();
 }
Ejemplo n.º 26
0
        public async Task ClearAsync()
        {
            await inner.ClearAsync();

            cache.Clear();
        }
Ejemplo n.º 27
0
        static void LRUCacheTest()
        {
            try
            {
                bool   runForever = true;
                byte[] data       = InitByteArray(_DataLength, 0x00);
                byte[] keyData;

                LRUCache <string, byte[]> cache = new LRUCache <string, byte[]>(_Capacity, _EvictCount);
                Thread.Sleep(250);

                while (runForever)
                {
                    Console.Write("Command [LRU] > ");
                    string userInput = Console.ReadLine();
                    if (String.IsNullOrEmpty(userInput))
                    {
                        continue;
                    }

                    switch (userInput.ToLower())
                    {
                    case "?":
                        MenuLRU();
                        break;

                    case "get":
                        Console.Write("Key > ");
                        string getKey = Console.ReadLine();
                        if (String.IsNullOrEmpty(getKey))
                        {
                            break;
                        }
                        if (cache.TryGet(getKey, out keyData))
                        {
                            Console.WriteLine("Cache hit");
                        }
                        else
                        {
                            Console.WriteLine("Cache miss");
                        }
                        break;

                    case "all":
                        Dictionary <string, byte[]> dump = cache.All();
                        if (dump != null && dump.Count > 0)
                        {
                            foreach (KeyValuePair <string, byte[]> entry in dump)
                            {
                                Console.WriteLine(entry.Key);
                            }
                            Console.WriteLine("Count: " + dump.Count + " entries");
                        }
                        else
                        {
                            Console.WriteLine("Empty");
                        }
                        break;

                    case "load":
                        DateTime startTime = DateTime.Now;

                        for (int i = 0; i < _LoadCount; i++)
                        {
                            string loadKey = Guid.NewGuid().ToString();
                            Console.Write("Adding entry " + i + " of " + _LoadCount + "                      \r");
                            cache.AddReplace(loadKey, data);
                        }

                        Console.WriteLine(
                            "Loaded " + _LoadCount +
                            " records in " + TotalTimeFrom(startTime) + ": " +
                            DecimalToString(TotalMsFrom(startTime) / _LoadCount) + "ms per entry");
                        break;

                    case "last_used":
                        Console.WriteLine("Last used key: " + cache.LastUsed());
                        break;

                    case "first_used":
                        Console.WriteLine("First used key: " + cache.FirstUsed());
                        break;

                    case "oldest":
                        Console.WriteLine("Oldest key: " + cache.Oldest());
                        break;

                    case "newest":
                        Console.WriteLine("Newest key: " + cache.Newest());
                        break;

                    case "count":
                        Console.WriteLine("Cache count: " + cache.Count());
                        break;

                    case "clear":
                        cache.Clear();
                        Console.WriteLine("Cache cleared");
                        break;

                    case "q":
                    case "quit":
                        runForever = false;
                        break;

                    default:
                        continue;
                    }
                }

                Console.WriteLine("Goodbye!");
                return;
            }
            catch (Exception e)
            {
                PrintException(e);
            }
            finally
            {
                Console.WriteLine("");
                Console.Write("Press ENTER to exit.");
                Console.ReadLine();
            }
        }