Esempio n. 1
0
 public void TestAddCache()
 {
     var cacheManager = CacheAdapterFactory.CreateCache();
     cacheManager.OnAdd += CacheManager_OnAdd;
     cacheManager.Clear();
     for (int i = 1; i <= 1000; i++)
     {
         var user = new User() { Id = i, Name = "user" + i };
         Assert.IsTrue(cacheManager.Add("user" + i, user, "login"));
     }
     //cacheManager.ClearRegion("login");
 }
Esempio n. 2
0
 public void TestGetCache()
 {
     var cacheManager = CacheAdapterFactory.CreateCache();
     cacheManager.Clear();
     for (int i = 1; i <= 10; i++)
     {
         var user = new User() { Id = i, Name = "user" + i };
         Assert.IsTrue(cacheManager.Add("user" + i, user, "login"));
     }
     for (int i = 1; i <= 10; i++)
     {
         var user= cacheManager.Get<User>("user" + i,"login");
         Assert.IsInstanceOfType(user, typeof(User));
     }
     cacheManager.ClearRegion("login");
 }
Esempio n. 3
0
 public void TestSetAbsoluteExpireCache()
 {
     var cacheManager = CacheAdapterFactory.CreateCache();
     for (int i = 1; i <= 10; i++)
     {
         var user = new User() { Id = i, Name = "user" + i };
         Assert.IsTrue(cacheManager.Add("user" + i, user, "login"));
     }
     for (int i = 1; i <= 10; i++)
     {
         cacheManager.Expire("user" + i, "login", ExpirationMode.Absolute,TimeSpan.FromMinutes(1));
         cacheManager.Expire("user" + i, "login", DateTimeOffset.Now.AddMinutes(1));
     }
     Thread.Sleep(5000);
     for (int i = 1; i <= 10; i++)
     {
         var user = cacheManager.Get<User>("user" + i, "login");
         Assert.IsInstanceOfType(user, typeof(User));
     }
 }