Beispiel #1
0
        public void AddAndGetTest()
        {
            var cache = new SqlCache();

            cache.Add(typeof(TestModel), "SELECT", null, null, "Test");
            Assert.AreEqual(1, cache.Count);

            var sql = cache.Get(typeof(TestModel), "SELECT", null, null);

            Assert.AreEqual("Test", sql.SqlString);
        }
Beispiel #2
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 #3
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 #7
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 #8
0
        public void GetItem()
        {
            // ARRANGE
            string   key   = "GetItem";
            string   data  = "data";
            SqlCache cache = new SqlCache(connectionString);

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

            // ACT
            var getData = cache.Get(key);

            // ASSERT
            Assert.AreEqual(data, getData);
        }
Beispiel #9
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 #10
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 #11
0
        public void GetCount()
        {
            // ARRANGE
            SqlCache cache = new SqlCache(connectionString);

            cache.Add("1", "GetCountValue1", DateTime.Now.AddMinutes(30));
            cache.Set("2", "GetCountValue2", new System.Runtime.Caching.CacheItemPolicy {
                AbsoluteExpiration = DateTimeOffset.Now.AddMinutes(1)
            });

            cache.Set("3", "GetCountValue3", new System.Runtime.Caching.CacheItemPolicy {
                SlidingExpiration = TimeSpan.FromMinutes(1)
            });
            // ACT
            var count = cache.GetCount();

            // ASSERT
            Assert.AreEqual(3, count);
        }
Beispiel #12
0
        public void GetEnumerable()
        {
            // ARRANGE
            var      values = new string[] { "GetEnumerableValue1", "GetEnumerableValue2", "GetEnumerableValue3" };
            SqlCache cache  = new SqlCache(connectionString);

            cache.Add("1", values[0], DateTime.Now.AddMinutes(30));
            cache.Set("2", values[0], new System.Runtime.Caching.CacheItemPolicy {
                AbsoluteExpiration = DateTimeOffset.Now.AddMinutes(1)
            });

            cache.Set("3", values[0], new System.Runtime.Caching.CacheItemPolicy {
                SlidingExpiration = TimeSpan.FromMinutes(1)
            });
            // ACT
            foreach (var item in cache)
            {
                // ASSERT
                Assert.IsTrue(values.Any(x => x == item.Value.ToString()));
            }
        }
        /// <summary>
        /// Ìí¼ÓInt32»º´æ¡£
        /// </summary>
        /// <param name="sql">SQLÓï¾ä</param>
        /// <param name="n">´ý»º´æÕûÊý</param>
        /// <param name="tableNames">±íÃûÊý×é</param>
        public static void Add(String sql, Int32 n, String[] tableNames)
        {
            //¹Ø±Õ»º´æ
            if (CacheType == XCacheType.Close)
            {
                return;
            }
            //ÇëÇ󼶻º´æ
            if (CacheType == XCacheType.RequestCache)
            {
                if (HttpContext.Current == null)
                {
                    return;
                }
                HttpContext.Current.Items.Add("XCache_Int32_" + sql, new CacheItem <Int32>(tableNames, n));
                return;
            }
            //¾²Ì¬»º´æ
            if (_IntCache.ContainsKey(sql))
            {
                return;
            }
            lock (_IntCache)
            {
                if (_IntCache.ContainsKey(sql))
                {
                    return;
                }

                _IntCache.Add(sql, new CacheItem <Int32>(tableNames, n));
            }
            //´øÓÐЧÆÚ
            if (CacheType == XCacheType.Period)
            {
                CreateTimer();
            }
        }