Exemplo n.º 1
0
        public void CanSetAnExistingEntry()
        {
            var mCache = new DefaultMemCached(10);
            mCache.Set("X", "Y");
            mCache.Set("X", "Z");

            Assert.AreEqual("Z", mCache.Get("X"));
        }
Exemplo n.º 2
0
        /**
         * TODO:
         *
         *      - Introduce Unity and use Dependency Injection
         *      - Stress tests
         *      - Manage exceptions
         *      - Preallocate all the needed memoory at the startup (if possible)
         *      - Implement different versions and compare their performances
         *
         */
        static void Main(string[] args)
        {
            IMemCached memCached = new DefaultMemCached(10);

            memCached.Set("A", "Apple");
            memCached.Set("B", "Bubble");
            memCached.Set("C", "Cat");

            memCached.Set("B", "Many Bubbles");
            memCached.Set("C", "A lot of Cats");

            System.Console.WriteLine("'B' is " + memCached.Get("B"));
            System.Console.WriteLine("'C' is " + memCached.Get("C"));
        }
Exemplo n.º 3
0
        public void CanSetAndGetAnEntry()
        {
            var mCache = new DefaultMemCached(10);
            mCache.Set("X", "Y");

            Assert.AreEqual("Y", mCache.Get("X"));
            Assert.IsNull(mCache.Get("Y"));
        }
Exemplo n.º 4
0
        public void GettingAKeyChangesItsPriority()
        {
            const int size = 5;
            var mCache = new DefaultMemCached(size);
            for (var i = 1; i <= size; ++i)
            {
                mCache.Set("K" + i, i.ToString());
            }
            mCache.Get("K1");
            mCache.Set("K6", "6");
            mCache.Set("K7", "7");

            Assert.IsNotNull(mCache.Get("K1"));
            Assert.IsNull(mCache.Get("K2"));
            Assert.IsNull(mCache.Get("K3"));
            Assert.IsNotNull(mCache.Get("K4"));
        }
Exemplo n.º 5
0
        public void CanDeleteAnEntry()
        {
            var mCache = new DefaultMemCached(10);
            mCache.Set("X", "Y");

            Assert.IsNotNull(mCache.Get("X"));
            mCache.Delete("X");
            Assert.IsNull(mCache.Get("X"));
        }
Exemplo n.º 6
0
        public void OldestMessagesAreEvicted()
        {
            const int size = 5;
            var mCache = new DefaultMemCached(size);
            for (var i = 1; i <= size + 2; ++i)
            {
                mCache.Set("K" + i, i.ToString());
            }

            Assert.IsNull(mCache.Get("K1"));
            Assert.IsNull(mCache.Get("K2"));
            Assert.IsNotNull(mCache.Get("K3"));
        }