Exemplo n.º 1
0
        private static async Task <bool> CreateUpdateItem(object cacheKey, object cacheObject, string region, CacheItemPolicy cacheItemPolicy, ICacheOptions cacheOptions)
        {
            var key       = MemoryUtilities.CombinedKey(cacheKey, region);
            var cacheItem = new CacheObject
            {
                Item = await MemoryStreamHelper.SerializeObject(cacheObject)
            };

            bool results;

            lock (Sync)
            {
                results = _cache.Add(key, cacheItem, cacheItemPolicy);
            }

            return(results);
        }
Exemplo n.º 2
0
        private static async Task <bool> CreateUpdateItem(object cacheKey, object cacheObject, string region, int expireCacheTime, CacheItemPolicy cacheItemPolicy, bool allowSliddingTime = false)
        {
            var cacheData = await MemoryStreamHelper.SerializeObject(cacheObject);

            var key        = MemoryUtilities.CombinedKey(cacheKey, region);
            var expireTime = DateTime.UtcNow.AddMinutes(expireCacheTime);
            var item       = new BaseModel
            {
                CacheKey          = key,
                Expires           = expireTime,
                CacheObject       = cacheData,
                AllowSliddingTime = allowSliddingTime
            };

            bool results;

            lock (Sync)
            {
                results = _cache.Add(key, item, cacheItemPolicy);
            }

            return(results);
        }
Exemplo n.º 3
0
 /// <summary>
 /// Check if the item exist
 /// </summary>
 /// <param name="cacheKey"></param>
 /// <param name="region"></param>
 /// <returns>true false</returns>
 public override Task <bool> Exist(object cacheKey, string region)
 {
     return(!_isEnabled?
            Task.FromResult(false) :
                Task.FromResult(_cache[MemoryUtilities.CombinedKey(cacheKey, region)] != null));
 }