/// <summary> /// Returns cache options for absolute expiration. /// </summary> /// <remarks> /// A cached value might expire sooner than the specified time. /// </remarks> /// <param name="absoluteExpirationTime">The absolute time when the cached value /// will expire</param> /// <returns></returns> public static CacheOptions AbsoluteExpiration(DateTime absoluteExpirationTime) { CacheOptions options = new CacheOptions(); options.absoluteExpirationTime = absoluteExpirationTime; return(options); }
/// <summary> /// Returns cache options for sliding expiration. /// </summary> /// <remarks> /// A cached value might expire sooner than the specified time. /// </remarks> /// <param name="slidingExpirationTimeSpan">The time when a cached value will /// expire relative to the time it was added to the cache</param> /// <returns>The cache options</returns> public static CacheOptions SlidingExpiration(TimeSpan slidingExpirationTimeSpan) { CacheOptions options = new CacheOptions(); options.slidingExpirationTimeSpan = slidingExpirationTimeSpan; return(options); }
/// <inheritdoc /> protected override void InternalSet(string key, object value, CacheOptions options) { DateTime expirationTime = options.GetUtcExpirationTimeRelativeToNow(); lock (items) { items[key] = new CacheItem(value, expirationTime); if (expirationTime < nextExpirationTime) { nextExpirationTime = expirationTime; } } }
/// <inheritdoc /> public void Set(string key, object value, CacheOptions options) { if (key == null) { throw new ArgumentNullException("key"); } if (key.Length == 0) { throw new ArgumentException("Key must not be empty.", "key"); } if (value == null) { throw new ArgumentNullException("value"); } InternalSet(key, value, options); }
/// <summary> /// Returns cache options for absolute expiration. /// </summary> /// <remarks> /// A cached value might expire sooner than the specified time. /// </remarks> /// <param name="absoluteExpirationTime">The absolute time when the cached value /// will expire</param> /// <returns></returns> public static CacheOptions AbsoluteExpiration(DateTime absoluteExpirationTime) { CacheOptions options = new CacheOptions(); options.absoluteExpirationTime = absoluteExpirationTime; return options; }
/// <summary> /// Returns cache options for sliding expiration. /// </summary> /// <remarks> /// A cached value might expire sooner than the specified time. /// </remarks> /// <param name="slidingExpirationTimeSpan">The time when a cached value will /// expire relative to the time it was added to the cache</param> /// <returns>The cache options</returns> public static CacheOptions SlidingExpiration(TimeSpan slidingExpirationTimeSpan) { CacheOptions options = new CacheOptions(); options.slidingExpirationTimeSpan = slidingExpirationTimeSpan; return options; }
/// <inheritdoc /> protected override void InternalSet(string key, object value, CacheOptions options) { innerCache.Set(partitionPrefix + key, value, options); }
/// <inheritdoc /> protected override void InternalSet(string key, object value, CacheOptions options) { }
/// <summary> /// Internal implementation of <see cref="Set(string, object, CacheOptions)" />. /// All parameters have been validated by the base class. /// </summary> /// <param name="key">The cache key</param> /// <param name="value">The value to set, must not be null</param> /// <param name="options">The cache options for the value</param> protected abstract void InternalSet(string key, object value, CacheOptions options);
/// <inheritdoc /> protected override void InternalSet(string key, object value, CacheOptions options) { DateTime expirationTime = options.GetUtcExpirationTimeRelativeToNow(); lock (items) { items[key] = new CacheItem(value, expirationTime); if (expirationTime < nextExpirationTime) nextExpirationTime = expirationTime; } }
/// <inheritdoc /> public void Set(string key, object value, CacheOptions options) { if (key == null) throw new ArgumentNullException("key"); if (key.Length == 0) throw new ArgumentException("Key must not be empty.", "key"); if (value == null) throw new ArgumentNullException("value"); InternalSet(key, value, options); }