Example #1
0
        public T GetOrAdd <T>(string key, Func <T> valueFactory, CacheItemOptions options = null)
        {
            var item = Get <T>(key);

            if (Equals(item, default(T)))
            {
                item = valueFactory();
                Put(key, item, options);
            }

            return(item);
        }
Example #2
0
        public CacheItem(string value, CacheItemOptions options = null)
        {
            Value = value;

            if (options == null)
            {
                return;
            }

            ExpiresIn = options.ExpiresIn;
            Replace   = options.Replace;
            Add       = options.Add;
            Cas       = options.Cas;
        }
Example #3
0
        /// <summary>
        /// Gets the item from the cache, or initializes the cache item's value using the specififed <paramref name="valueFactory"/>.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="key">The cache item's key.</param>
        /// <param name="valueFactory">The method invoked to create the value</param>
        /// <param name="options">The options.</param>
        /// <returns></returns>
        public async Task <T> GetOrAdd <T>(string key, Func <T> valueFactory, CacheItemOptions options = null)
        {
            T item = await Get <T>(key);

            if (Equals(item, default(T)))
            {
                item = valueFactory();

                await Put(key, item, options);

                return(item);
            }

            return(item);
        }
Example #4
0
 public bool Put(string key, string value, CacheItemOptions options = null)
 {
     return(Put(key, new CacheItem(value, options)));
 }
Example #5
0
 public bool Put(string key, object value, CacheItemOptions options = null)
 {
     return(Put(key, ValueSerializer.Generate(value), options));
 }
Example #6
0
 public async Task <bool> Put(string key, string value, CacheItemOptions options = null)
 {
     return(await Put(key, new CacheItem(value, options)));
 }
Example #7
0
 public async Task <bool> Put(string key, object value, CacheItemOptions options = null)
 {
     return(await Put(key, ValueSerializer.Generate(value), options));
 }