public void Add(string key, object item, int lifeLength) { var ci = new CacheItem(this, _config.Duration, lifeLength) { Data = item }; if (!string.IsNullOrEmpty(key)) { Items.AddOrUpdate(key, ci, (oldKey, oldValue) => ci); } }
public async Task <object> TryGetOrSetAsync(string key, Func <object> initializer, int lifeLength, Func <object, Task <bool> > condition) { var result = await TryGetAsync(key, condition); if (result == null && !string.IsNullOrEmpty(key)) { var ci = new CacheItem(this, _config.Duration, lifeLength) { Data = initializer() }; var x = Items.AddOrUpdate(key, (k) => ci, (oldKey, oldValue) => ci); result = x.Data; } return(result); }
public object GetOrSet(string key, Func <object> initializer, int lifeLength) { var result = Get(key); if (result == null && !string.IsNullOrEmpty(key)) { var ci = new CacheItem(this, _config.Duration, lifeLength) { Data = initializer() }; var x = Items.AddOrUpdate(key, (k) => ci, (oldKey, oldValue) => ci); result = x.Data; } return(result); }
public void Add(string header, string value) { Items.AddOrUpdate(header.ToLower(), new KeyValuePair <string, string>(header, value), (x, old) => new KeyValuePair <string, string>(header, value)); }