예제 #1
0
        public void Serialize_Should_Succeed()
        {
            var res = _serializer.Serialize(new Model {
                Prop = "abc"
            });

            Assert.NotEmpty(res);
        }
예제 #2
0
        /// <summary>
        /// Set the specified cacheKey, cacheValue and expiration.
        /// </summary>
        /// <returns>The set.</returns>
        /// <param name="cacheKey">Cache key.</param>
        /// <param name="cacheValue">Cache value.</param>
        /// <param name="expiration">Expiration.</param>
        /// <typeparam name="T">The 1st type parameter.</typeparam>
        public void Set <T>(string cacheKey, T cacheValue, TimeSpan expiration) where T : class
        {
            ArgumentCheck.NotNullOrWhiteSpace(cacheKey, nameof(cacheKey));
            ArgumentCheck.NotNull(cacheValue, nameof(cacheValue));
            ArgumentCheck.NotNegativeOrZero(expiration, nameof(expiration));

            _cache.StringSet(
                cacheKey,
                _serializer.Serialize(cacheValue),
                expiration);
        }
예제 #3
0
        /// <summary>
        /// Publish the specified channel, cacheKey, cacheValue and expiration.
        /// </summary>
        /// <returns>The publish.</returns>
        /// <param name="channel">Channel.</param>
        /// <param name="cacheKey">Cache key.</param>
        /// <param name="cacheValue">Cache value.</param>
        /// <param name="expiration">Expiration.</param>
        public void Publish <T>(string channel, string cacheKey, T cacheValue, TimeSpan expiration)
        {
            ArgumentCheck.NotNullOrWhiteSpace(channel, nameof(channel));

            //TODO : Handle Parameters
            EasyCachingMessage message = new EasyCachingMessage()
            {
                CacheKey   = cacheKey,
                CacheValue = cacheValue,
                Expiration = expiration
            };

            _subscriber.Publish(channel, _serializer.Serialize(message));
        }
예제 #4
0
        /// <summary>
        /// Set the specified cacheKey, cacheValue and expiration.
        /// </summary>
        /// <returns>The set.</returns>
        /// <param name="cacheKey">Cache key.</param>
        /// <param name="cacheValue">Cache value.</param>
        /// <param name="expiration">Expiration.</param>
        /// <typeparam name="T">The 1st type parameter.</typeparam>
        public void Set <T>(string cacheKey, T cacheValue, TimeSpan expiration) where T : class
        {
            ArgumentCheck.NotNullOrWhiteSpace(cacheKey, nameof(cacheKey));
            ArgumentCheck.NotNull(cacheValue, nameof(cacheValue));
            ArgumentCheck.NotNegativeOrZero(expiration, nameof(expiration));

            if (MaxRdSecond > 0)
            {
                var addSec = new Random().Next(1, MaxRdSecond);
                expiration.Add(new TimeSpan(0, 0, addSec));
            }

            _cache.StringSet(
                cacheKey,
                _serializer.Serialize(cacheValue),
                expiration);
        }
        /// <summary>
        /// Set the specified cacheKey, cacheValue and expiration.
        /// </summary>
        /// <returns>The set.</returns>
        /// <param name="cacheKey">Cache key.</param>
        /// <param name="cacheValue">Cache value.</param>
        /// <param name="expiration">Expiration.</param>
        /// <typeparam name="T">The 1st type parameter.</typeparam>
        public override void BaseSet <T>(string cacheKey, T cacheValue, TimeSpan expiration)
        {
            ArgumentCheck.NotNullOrWhiteSpace(cacheKey, nameof(cacheKey));
            ArgumentCheck.NotNull(cacheValue, nameof(cacheValue));
            ArgumentCheck.NotNegativeOrZero(expiration, nameof(expiration));

            if (MaxRdSecond > 0)
            {
                var addSec = new Random().Next(1, MaxRdSecond);
                expiration = expiration.Add(TimeSpan.FromSeconds(addSec));
            }

            _cache.StringSet(
                cacheKey,
                _serializer.Serialize(cacheValue),
                expiration);
        }
예제 #6
0
        protected override void Exec(IEasyCachingSerializer serializer)
        {
            var data   = serializer.Serialize(_list);
            var result = serializer.Deserialize <List <MyPoco> >(data);

            if (result == null)
            {
                throw new Exception();
            }
        }
        /// <summary>
        /// Publish the specified topic and message.
        /// </summary>
        /// <param name="topic">Topic.</param>
        /// <param name="message">Message.</param>
        public override void BasePublish(string topic, EasyCachingMessage message)
        {
            var channel = _pubChannelPool.Get();

            try
            {
                var body = _serializer.Serialize(message);

                channel.ExchangeDeclare(_options.TopicExchangeName, ExchangeType.Topic, true, false, null);
                channel.BasicPublish(_options.TopicExchangeName, topic, false, null, body);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            finally
            {
                _pubChannelPool.Return(channel);
            }
        }
예제 #8
0
        /// <summary>
        /// Publish the specified topic and message.
        /// </summary>
        /// <param name="topic">Topic.</param>
        /// <param name="message">Message.</param>
        public void Publish(string topic, EasyCachingMessage message)
        {
            var conn = _pubConnectionPool.Get();

            try
            {
                var body  = _serializer.Serialize(message);
                var model = conn.CreateModel();

                model.ExchangeDeclare(_options.TopicExchangeName, ExchangeType.Topic, true, false, null);
                model.BasicPublish(_options.TopicExchangeName, topic, false, null, body);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            finally
            {
                _pubConnectionPool.Return(conn);
            }
        }
        public void Set_Value_Should_Succeed()
        {
            var cacheKey   = Guid.NewGuid().ToString();
            var cacheValue = "value";
            var cacheBytes = new byte[] { 0x01 };

            A.CallTo(() => _serializer.Serialize(cacheValue)).Returns(cacheBytes);
            A.CallTo(() => _serializer.Deserialize <string>(A <byte[]> .Ignored)).Returns(cacheValue);

            _provider.Set(cacheKey, cacheValue, _defaultTs);

            var val = _provider.Get <string>(cacheKey, null, _defaultTs);

            Assert.NotNull(val);
            Assert.Equal(cacheValue, val.Value);
        }
예제 #10
0
        /// <summary>
        /// Publish the specified channel and message.
        /// </summary>
        /// <returns>The publish.</returns>
        /// <param name="channel">Channel.</param>
        /// <param name="message">Message.</param>
        public void Publish(string channel, EasyCachingMessage message)
        {
            var _publisherChannel = _connectionChannelPool.Rent();

            try
            {
                var body = _serializer.Serialize(message);

                _publisherChannel.ExchangeDeclare(_rabbitMQBusOptions.TopicExchangeName, ExchangeType.Topic, true, false, null);
                _publisherChannel.BasicPublish(_rabbitMQBusOptions.TopicExchangeName, channel, false, null, body);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            finally
            {
                var returned = _connectionChannelPool.Return(_publisherChannel);
                if (!returned)
                {
                    _publisherChannel.Dispose();
                }
            }
        }
예제 #11
0
        /// <summary>
        /// Publish the specified topic and message.
        /// </summary>
        /// <param name="topic">Topic.</param>
        /// <param name="message">Message.</param>
        public void Publish(string topic, EasyCachingMessage message)
        {
            ArgumentCheck.NotNullOrWhiteSpace(topic, nameof(topic));

            _subscriber.Publish(topic, _serializer.Serialize(message));
        }
예제 #12
0
        /// <summary>
        /// Publish the specified channel and message.
        /// </summary>
        /// <returns>The publish.</returns>
        /// <param name="channel">Channel.</param>
        /// <param name="message">Message.</param>
        public void Publish(string channel, EasyCachingMessage message)
        {
            ArgumentCheck.NotNullOrWhiteSpace(channel, nameof(channel));

            _subscriber.Publish(channel, _serializer.Serialize(message));
        }
예제 #13
0
        /// <inheritdoc/>
        public byte[] Serialize <T>(T value)
        {
            var bytes = _easyCachingSerializer.Serialize(value);

            return(_compressor.Compress(bytes));
        }