public void FutureTest() { var db = new TrackerDataContext { Log = Console.Out }; CacheSettings cache = new CacheSettings(120); // build up queries var q1 = db.User .ByEmailAddress("*****@*****.**") .FutureCache(cache); var q2 = db.Task .Where(t => t.Summary == "Test") .FutureCache(cache); // this triggers the loading of all the future queries var users = q1.ToList(); Assert.IsNotNull(users); // this should already be loaded Assert.IsNotNull(q2); var tasks = q2.ToList(); Assert.IsNotNull(tasks); // queries are loaded and cached, run same queries again... var c1 = db.User .ByEmailAddress("*****@*****.**") .FutureCache(cache); var c2 = db.Task .Where(t => t.Summary == "Test") .FutureCache(cache); // should be loaded because it came from cache Assert.IsNotNull(c1); Assert.IsNotNull(c2); users = c1.ToList(); Assert.IsNotNull(users); tasks = c2.ToList(); Assert.IsNotNull(tasks); }
public static CacheSettings WithGroup(this CacheSettings settings, string group) { settings.Group = group; return(settings); }
public static CacheSettings WithProvider(this CacheSettings settings, string provider) { settings.Provider = provider; return(settings); }
public static CacheSettings WithCacheItemRemovedCallback(this CacheSettings settings, CacheItemRemovedCallback cacheItemRemovedCallback) { settings.CacheItemRemovedCallback = cacheItemRemovedCallback; return(settings); }
/// <summary> /// Saves the specified key to the default cache provider for a specific duration. /// </summary> /// <typeparam name="T">The type for data being saved,</typeparam> /// <param name="key">The key used to store the data in the cache provider.</param> /// <param name="data">The data to be cached in the provider.</param> /// <param name="duration">The duration to store the data in the cache.</param> public static void Set <T>(string key, T data, int duration) { DefaultProvider.Set(key, data, CacheSettings.FromDuration(duration)); }
/// <summary> /// Converts the profile element to a <see cref="CacheSettings"/> instance. /// </summary> /// <returns>An instance of <see cref="CacheSettings"/>.</returns> public CacheSettings ToCacheSettings() { var cache = new CacheSettings(); cache.Duration = Duration; cache.Mode = Mode; if (!string.IsNullOrEmpty(Provider)) cache.Provider = Provider; if (!string.IsNullOrEmpty(Group)) cache.Group = Group; return cache; }
public static CacheSettings WithCacheDependency(this CacheSettings settings, CacheDependency cacheDependency) { settings.CacheDependency = cacheDependency; return(settings); }
public static CacheSettings WithPriority(this CacheSettings settings, CacheItemPriority priority) { settings.Priority = priority; return(settings); }
public void FromCacheFutre() { var db = new TrackerDataContext { Log = Console.Out }; CacheSettings cache = new CacheSettings(120); // build up queries var q1 = db.Task .Where(t => t.Summary == "Test") .FromCache(cache) .ToList(); // duplicate query except count var q2 = db.Task .Where(t => t.Summary == "Test") .FutureCache(120); var q3 = db.Task .Where(t => t.Summary == "Test") .FutureCacheCount(cache); var count = q3.Value; Assert.Greater(count, 0); var tasks = q2.ToList(); Assert.IsNotNull(tasks); Assert.AreEqual(q1.Count, tasks.Count); }
public void FutureValueReverseTest() { var db = new TrackerDataContext { Log = Console.Out }; CacheSettings cache = new CacheSettings(120); // build up queries var q1 = db.User .Where(u => u.EmailAddress == "*****@*****.**") .FutureCacheFirstOrDefault(cache); var q2 = db.Task .Where(t => t.Summary == "Test") .FutureCacheCount(cache); // duplicate query except count var q3 = db.Task .Where(t => t.Summary == "Test") .FutureCache(cache); // access q2 first to trigger loading, testing loading from FutureCount // this triggers the loading of all the future queries var count = q2.Value; Assert.Greater(count, 0); // this should already be loaded Assert.IsTrue(((IFutureQuery)q1).IsLoaded); var user = q1.Value; Assert.IsNotNull(user); var tasks = q3.ToList(); Assert.IsNotNull(tasks); // queries are loaded and cached, run same queries again... var c1 = db.User .ByEmailAddress("*****@*****.**") .FutureCacheFirstOrDefault(cache); var c2 = db.Task .Where(t => t.Summary == "Test") .FutureCacheCount(cache); var c3 = db.Task .Where(t => t.Summary == "Test") .FutureCache(cache); // should be loaded because it came from cache Assert.IsTrue(c1.IsLoaded); Assert.IsTrue(c2.IsLoaded); Assert.IsNotNull(c3); user = c1.Value; Assert.IsNotNull(user); count = c2.Value; Assert.Greater(count, 0); tasks = c3.ToList(); Assert.IsNotNull(tasks); }
/// <summary> /// Saves a key/value pair to the cache if the key does not already exist. /// </summary> /// <typeparam name="T">The type for data being retrieved from cache,</typeparam> /// <param name="key">The key used to store the data in the cache provider.</param> /// <param name="valueFactory">The function used to generate a value for the key.</param> /// <param name="settings">The <see cref="CacheSettings"/> to be used when storing in the provider.</param> /// <returns> /// An instance of T that will be either the existing value for the key if the key is already in the cache, /// or the new value if the key was not in the cache. /// </returns> public static T GetOrSet <T>(string key, Func <string, T> valueFactory, CacheSettings settings) { return(DefaultProvider.GetOrSet(key, valueFactory, settings)); }
/// <summary> /// Saves a key/value pair to the cache if the key does not already exist. /// </summary> /// <typeparam name="T">The type for data being retrieved from cache,</typeparam> /// <param name="key">The key used to store the data in the cache provider.</param> /// <param name="data">The data to be cached in the provider.</param> /// <param name="settings">The <see cref="CacheSettings"/> to be used when storing in the provider.</param> /// <returns> /// An instance of T that will be either the existing value for the key if the key is already in the cache, /// or the new value if the key was not in the cache. /// </returns> public static T GetOrSet <T>(string key, T data, CacheSettings settings) { return(DefaultProvider.GetOrSet(key, data, settings)); }
/// <summary> /// Saves the specified key using the settings from the specified cache profile. /// </summary> /// <typeparam name="T">The type for data being saved,</typeparam> /// <param name="key">The key used to store the data in the cache provider.</param> /// <param name="data">The data to be cached in the provider.</param> /// <param name="settings">The <see cref="CacheSettings"/> to be used when storing in the provider.</param> public static void Set <T>(string key, T data, CacheSettings settings) { GetProvider(settings.Provider).Set(key, data, settings); }
/// <summary> /// Saves the specified key using the settings from the specified cache profile. /// </summary> /// <typeparam name="T">The type for data being saved,</typeparam> /// <param name="key">The key used to store the data in the cache provider.</param> /// <param name="data">The data to be cached in the provider.</param> /// <param name="profile">The name of the cache profile to use.</param> public static void Set <T>(string key, T data, string profile) { CacheSettings settings = GetProfile(profile); GetProvider(settings.Provider).Set(key, data, settings); }
public static CacheSettings WithDuration(this CacheSettings settings, TimeSpan duration) { settings.Duration = duration; settings.Mode = CacheExpirationMode.Duration; return(settings); }
public static CacheSettings WithAbsoluteExpiration(this CacheSettings settings, DateTime absoluteExpiration) { settings.AbsoluteExpiration = absoluteExpiration; settings.Mode = CacheExpirationMode.Absolute; return(settings); }
public void FutureCountTest() { var db = new TrackerDataContext { Log = Console.Out }; CacheSettings cache = new CacheSettings(120); // build up queries var q1 = db.User .ByEmailAddress("*****@*****.**") .FutureCache(cache); var q2 = db.Task .Where(t => t.Details == "Hello world!") .FutureCacheCount(cache); // this triggers the loading of all the future queries var users = q1.ToList(); Assert.IsNotNull(users); // this should already be loaded Assert.IsTrue(((IFutureQuery)q2).IsLoaded); var count = q2.Value; Assert.Greater(count, 0); // queries are loaded and cached, run same queries again... var c1 = db.User .ByEmailAddress("*****@*****.**") .FutureCache(cache); var c2 = db.Task .Where(t => t.Details == "Hello world!") .FutureCacheCount(cache); // should be loaded because it came from cache Assert.IsNotNull(c1); Assert.IsTrue(c2.IsLoaded); users = c1.ToList(); Assert.IsNotNull(users); count = c2.Value; Assert.Greater(count, 0); }
public static CacheSettings WithCacheEmptyResult(this CacheSettings settings, bool cacheEmptyResult) { settings.CacheEmptyResult = cacheEmptyResult; return(settings); }
public static CacheSettings WithDuration(this CacheSettings settings, int duration) { settings.Duration = TimeSpan.FromSeconds(duration); settings.Mode = CacheExpirationMode.Duration; return(settings); }
public static CacheSettings AddCacheDependency(this CacheSettings settings, params CacheDependency[] cacheDependencies) { return(AddCacheDependency(settings, (IEnumerable <CacheDependency>)cacheDependencies)); }
public static CacheSettings AddCacheDependency(this CacheSettings settings, params SqlCacheDependency[] cacheDependencies) { return(AddCacheDependency(settings, cacheDependencies.Cast <CacheDependency>())); }
/// <summary> /// Creates a new object that is a copy of the current instance. /// </summary> /// <returns> /// A new object that is a copy of this instance. /// </returns> public CacheSettings Clone() { var clone = new CacheSettings { Mode = Mode, Duration = Duration, AbsoluteExpiration = AbsoluteExpiration, Priority = Priority, CacheEmptyResult = CacheEmptyResult, CacheDependency = CacheDependency, CacheItemRemovedCallback = CacheItemRemovedCallback, Provider = Provider, Group = Group }; if (String.IsNullOrEmpty(Group)) clone.Group = CacheManager.DefaultGroup; return clone; }
/// <summary> /// Saves the specified key to the cache provider. /// </summary> /// <typeparam name="T">The type for data being saved,</typeparam> /// <param name="key">The key used to store the data in the cache provider.</param> /// <param name="data">The data to be cached in the provider.</param> /// <param name="settings">The <see cref="CacheSettings"/> to be used when storing in the provider.</param> public abstract void Set <T>(string key, T data, CacheSettings settings);