/// <summary> /// Inserts a cache entry into the cache without overwriting any existing cache entry. /// </summary> /// <param name="key">A unique identifier for the cache entry.</param> /// <param name="value">The object to insert.</param> /// <param name="slidingExpiration">A span of time within which a cache entry must be accessed before the cache entry is evicted from the cache.</param> /// <returns> /// <c>true</c> if insertion succeeded, or <c>false</c> if there is an already an entry in the cache that has the same key as key. /// </returns> public bool Add(string key, object value, TimeSpan slidingExpiration) { var cachePolicy = CachePolicy.WithSlidingExpiration(slidingExpiration); return(Add(key, value, cachePolicy)); }
/// <summary> /// Gets the cache value for the specified key that is already in the dictionary or the new value for the key as returned by <paramref name="valueFactory"/>. /// </summary> /// <param name="key">A unique identifier for the cache entry.</param> /// <param name="valueFactory">The function used to generate a value to insert into cache.</param> /// <param name="slidingExpiration">A span of time within which a cache entry must be accessed before the cache entry is evicted from the cache.</param> /// <returns> /// The value for the key. This will be either the existing value for the key if the key is already in the dictionary, /// or the new value for the key as returned by <paramref name="valueFactory"/> if the key was not in the dictionary. /// </returns> public object GetOrAdd(string key, Func <string, object> valueFactory, TimeSpan slidingExpiration) { var policy = CachePolicy.WithSlidingExpiration(slidingExpiration); return(GetOrAdd(key, valueFactory, policy)); }
/// <summary> /// Inserts a cache entry into the cache overwriting any existing cache entry. /// </summary> /// <param name="key">A unique identifier for the cache entry.</param> /// <param name="value">The object to insert.</param> /// <param name="slidingExpiration">A span of time within which a cache entry must be accessed before the cache entry is evicted from the cache.</param> public void Set(string key, object value, TimeSpan slidingExpiration) { var policy = CachePolicy.WithSlidingExpiration(slidingExpiration); Set(key, value, policy); }
/// <summary> /// Gets the cache value for the specified key that is already in the dictionary or the new value if the key was not in the dictionary. /// </summary> /// <param name="key">A unique identifier for the cache entry.</param> /// <param name="value">The object to insert.</param> /// <param name="slidingExpiration">A span of time within which a cache entry must be accessed before the cache entry is evicted from the cache.</param> /// <returns> /// The value for the key. This will be either the existing value for the key if the key is already in the dictionary, /// or the new value if the key was not in the dictionary. /// </returns> public object GetOrAdd(string key, object value, TimeSpan slidingExpiration) { var policy = CachePolicy.WithSlidingExpiration(slidingExpiration); return(GetOrAdd(key, value, policy)); }