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); }
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; }
/// <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); }
public bool Put(string key, string value, CacheItemOptions options = null) { return(Put(key, new CacheItem(value, options))); }
public bool Put(string key, object value, CacheItemOptions options = null) { return(Put(key, ValueSerializer.Generate(value), options)); }
public async Task <bool> Put(string key, string value, CacheItemOptions options = null) { return(await Put(key, new CacheItem(value, options))); }
public async Task <bool> Put(string key, object value, CacheItemOptions options = null) { return(await Put(key, ValueSerializer.Generate(value), options)); }