public void DurationTest() { using (var db = new TrackerDataContext()) { var query = db.Role.Where(r => r.Name == "Test Role"); var key = query.GetHashKey(); var roles = query.FromCache(CacheSettings.FromDuration(2)).ToList(); var cache = CacheManager.Get <ICollection <Role> >(key); Assert.IsNotNull(cache); Assert.AreEqual(roles.Count, cache.Count); System.Threading.Thread.Sleep(3000); cache = CacheManager.Get <ICollection <Role> >(key); Assert.IsNull(cache); } }
public void DurationTest() { using (var db = new TrackerDataContext()) { var query = db.Role.Where(r => r.Name == "Test Role"); var key = query.Take(1).GetHashKey(); var role = query.FromCacheFirstOrDefault(CacheSettings.FromDuration(2)); var cache1 = CacheManager.Get<ICollection<Role>>(key); Assert.IsNotNull(cache1); Assert.AreEqual(role.Id, cache1.FirstOrDefault().Id); System.Threading.Thread.Sleep(3000); var cache2 = CacheManager.Get<ICollection<Role>>(key); Assert.IsNull(cache2); } }
private void OnSelected(object sender, LinqDataSourceStatusEventArgs e) { if (!EnableCache) { return; } if (e.Exception != null || e.Result == null) { return; } string key = GetKey(); object source = CacheManager.Get <object>(key); if (source != null) { return; } else { source = e.Result; } Debug.WriteLine("Cache Insert: " + key); if (!String.IsNullOrEmpty(CacheProfile)) { CacheManager.Set(key, source, CacheManager.GetProfile(CacheProfile)); } else if (Duration > 0) { CacheManager.Set(key, source, CacheSettings.FromDuration(Duration)); } else { CacheManager.Set(key, source); } }