예제 #1
0
 public override void Set(string key, object value, DateTime expiresAt)
 {
     try
     {
         var itemBytes = Serializer.Binary.Serialize(value) as byte[];
         var item      = new CacheItem()
         {
             ItemBytes = itemBytes
         };
         var serializedItem = Serializer.Json.Serialize(item);
         var cacheKey       = CacheKeyBuilder.GetCacheKey(key);
         Current.SetInternal(cacheKey, serializedItem, expiresAt);
     }
     catch (Exception ex)
     {
         Log.Warn("CacheBase.Set - failed, item not cached. Message: {0}", ex.Message);
     }
 }
예제 #2
0
        public override object Get(string key)
        {
            var    cacheKey = CacheKeyBuilder.GetCacheKey(key);
            object item     = null;

            try
            {
                var serializedItem = Current.GetInternal(cacheKey);
                if (serializedItem != null)
                {
                    var cacheItem = Serializer.Json.Deserialize(typeof(CacheItem), serializedItem) as CacheItem;
                    item = Serializer.Binary.Deserialize(null, cacheItem.ItemBytes);
                }
            }
            catch (Exception ex)
            {
                Log.Warn("CacheBase.Get - failed, item not cached. Message: {0}", ex.Message);
            }
            return(item);
        }