Ejemplo n.º 1
0
        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);
            }
        }
Ejemplo n.º 2
0
        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);
        }
Ejemplo n.º 3
0
        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);
        }
Ejemplo n.º 4
0
 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));
 }