Beispiel #1
0
        public void GetItem()
        {
            string key = "GetItem";
            string data = "data";
            SqlCache cache = new SqlCache(connectionString);
            cache.Add(key, data, DateTime.Now.AddMinutes(30));
            var getData = cache.Get(key);

            Assert.AreEqual(data, getData);

            cache.Remove(key); // Clean DB for further testing
        }
Beispiel #2
0
        public void AddItem()
        {
            string key = "AddItem";
            string data = "data";
            SqlCache cache = new SqlCache(connectionString);
            cache.Add(key, data, DateTime.Now.AddMinutes(30));
            var result = cache.Contains(key);

            Assert.AreEqual(result, true);

            cache.Remove(key); // Clean DB for further testing
        }
        public void GetItem()
        {
            var key   = "GetItem";
            var data  = "data";
            var cache = new SqlCache(connectionString, serializer);

            cache.Add(key, data, DateTime.Now.AddMinutes(30));
            var getData = cache.Get(key);

            Assert.AreEqual(data, getData);

            cache.Remove(key);             // Clean DB for further testing
        }
        public void RemoveItem()
        {
            var key   = "RemoveItem";
            var data  = "data";
            var cache = new SqlCache(connectionString, serializer);

            cache.Add(key, data, DateTime.Now.AddMinutes(30));

            cache.Remove(key);
            var result = cache.Contains(key);

            Assert.AreEqual(result, false);
        }
        public void AddItem()
        {
            var key   = "AddItem";
            var data  = "data";
            var cache = new SqlCache(connectionString, serializer);

            cache.Add(key, data, DateTime.Now.AddMinutes(30));
            var result = cache.Contains(key);

            Assert.AreEqual(result, true);

            cache.Remove(key);             // Clean DB for further testing
        }
Beispiel #6
0
        public void RemoveItem()
        {
            string key = "RemoveItem";
            string data = "data";
            SqlCache cache = new SqlCache(connectionString);

            cache.Add(key, data, DateTime.Now.AddMinutes(30));

            cache.Remove(key);
            var result = cache.Contains(key);

            Assert.AreEqual(result, false);
        }
Beispiel #7
0
        public void RemoveItem()
        {
            // ARRANGE
            string   key   = "RemoveItem";
            string   data  = "data";
            SqlCache cache = new SqlCache(connectionString);

            cache.Add(key, data, DateTime.Now.AddMinutes(30));

            // ACT
            cache.Remove(key);

            // ASSERT
            var result = cache.Get(key);

            Assert.IsNull(result);
        }
Beispiel #8
0
        public void AddItem()
        {
            // ACT
            string key  = "AddItem";
            string data = "data";

            // ACT
            SqlCache cache = new SqlCache(connectionString);

            cache.Add(key, data, DateTime.Now.AddMinutes(30));

            // ASSERT
            var result = cache.Contains(key);

            Assert.AreEqual(result, true);
            cache.Remove(key); // Clean DB for further testing
        }
Beispiel #9
0
        public void AddOrGetExisting()
        {
            string key = "AddOrGetExisting";
            string data = "data";
            SqlCache cache = new SqlCache(connectionString);

            // Try to get data
            var getData = cache.Get(key);
            Assert.IsNull(getData);

            // Add new entry
            getData = cache.AddOrGetExisting(key, data, DateTime.Now.AddMinutes(30));
            Assert.IsNull(getData);

            // Retrieve added entry
            getData = cache.AddOrGetExisting(key, data, DateTime.Now.AddMinutes(30));
            Assert.IsNotNull(getData);

            cache.Remove(key); // Clean DB for further testing
        }
        public void AddOrGetExisting()
        {
            var key   = "AddOrGetExisting";
            var data  = "data";
            var cache = new SqlCache(connectionString, serializer);

            // Try to get data
            var getData = cache.Get(key);

            Assert.IsNull(getData);

            // Add new entry
            getData = cache.AddOrGetExisting(key, data, DateTime.Now.AddMinutes(30));
            Assert.IsNull(getData);

            // Retrieve added entry
            getData = cache.AddOrGetExisting(key, data, DateTime.Now.AddMinutes(30));
            Assert.IsNotNull(getData);

            cache.Remove(key);             // Clean DB for further testing
        }
        /// <summary>
        /// ά»¤
        /// </summary>
        /// <param name="obj"></param>
        private static void Check(Object obj)
        {
            //¹Ø±Õ»º´æ¡¢ÓÀ¾Ã¾²Ì¬»º´æºÍÇëÇ󼶻º´æʱ£¬²»ÐèÒª¼ì²é
            if (CacheType != XCacheType.Period)
            {
                return;
            }

            if (_TableCache.Count > 0)
            {
                lock (_TableCache)
                {
                    if (_TableCache.Count > 0)
                    {
                        List <String> toDel = null;
                        foreach (String sql in _TableCache.Keys)
                        {
                            if (_TableCache[sql].CacheTime.AddSeconds(Expiration) < DateTime.Now)
                            {
                                if (toDel == null)
                                {
                                    toDel = new List <String>();
                                }
                                toDel.Add(sql);
                            }
                        }
                        if (toDel != null && toDel.Count > 0)
                        {
                            foreach (String sql in toDel)
                            {
                                _TableCache.Remove(sql);
                            }
                        }
                    }
                }
            }
            if (_IntCache.Count > 0)
            {
                lock (_IntCache)
                {
                    if (_IntCache.Count > 0)
                    {
                        List <String> toDel = null;
                        foreach (String sql in _IntCache.Keys)
                        {
                            if (_IntCache[sql].CacheTime.AddSeconds(Expiration) < DateTime.Now)
                            {
                                if (toDel == null)
                                {
                                    toDel = new List <String>();
                                }
                                toDel.Add(sql);
                            }
                        }
                        if (toDel != null && toDel.Count > 0)
                        {
                            foreach (String sql in toDel)
                            {
                                _IntCache.Remove(sql);
                            }
                        }
                    }
                }
            }
        }