Ejemplo n.º 1
0
        /// <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="absoluteExpiration">The fixed date and time at which the cache entry will expire.</param>
        public void Set(string key, object value, DateTimeOffset absoluteExpiration)
        {
            var policy = CachePolicy.WithAbsoluteExpiration(absoluteExpiration);

            Set(key, value, policy);
        }
Ejemplo n.º 2
0
        /// <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="absoluteExpiration">The fixed date and time at which the cache entry will expire.</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, DateTimeOffset absoluteExpiration)
        {
            var cachePolicy = CachePolicy.WithAbsoluteExpiration(absoluteExpiration);

            return(Add(key, value, cachePolicy));
        }
Ejemplo n.º 3
0
        /// <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="absoluteExpiration">The fixed date and time at which the cache entry will expire.</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, DateTimeOffset absoluteExpiration)
        {
            var policy = CachePolicy.WithAbsoluteExpiration(absoluteExpiration);

            return(GetOrAdd(key, valueFactory, policy));
        }