Beispiel #1
0
        public override object Add(string key, object entry, DateTime utcExpiry)
        {
            var item = LiteDbHelper.QueryAll <CacheItem>().Find(q => q.Key == key);

            if (item != null)
            {
                if (item.Expiration <= DateTime.Now)
                {
                    LiteDbHelper.Delete <CacheItem>(item.Id);
                }
                else
                {
                    return(BinarySerializer.Deserialize(item.Entry));
                }
            }


            LiteDbHelper.Add(new CacheItem
            {
                Key         = key,
                Entry       = BinarySerializer.Serialize(entry),
                Expiration  = utcExpiry,
                CreatedDate = DateTime.UtcNow
            });

            return(entry);
        }
Beispiel #2
0
        public override void Remove(string key)
        {
            var item = LiteDbHelper.QueryAll <CacheItem>().Find(q => q.Key == key);

            if (item != null)
            {
                LiteDbHelper.Delete <CacheItem>(item.Id);
            }
        }
Beispiel #3
0
        public override object Get(string key)
        {
            var item = LiteDbHelper.QueryAll <CacheItem>().Find(q => q.Key == key);

            if (item != null)
            {
                if (item.Expiration <= DateTime.Now)
                {
                    LiteDbHelper.Delete <CacheItem>(item.Id);
                }
                else
                {
                    return(BinarySerializer.Deserialize(item.Entry));
                }
            }

            return(null);
        }