Ejemplo n.º 1
0
        private byte[] SerializeAndZip <TResult>(RedisObject <TResult> item)
        {
            using (var ms = new MemoryStream())
            {
                using (var compressionStream = new GZipStream(ms, CompressionMode.Compress))
                {
                    using (var zipStreamWriter = new StreamWriter(compressionStream))
                    {
                        _serializer.Serialize(zipStreamWriter, item);
                    }
                }

                return(ms.ToArray());
            }
        }
Ejemplo n.º 2
0
        public async Task StoreAsync <TResult>(Core.Util.ProxiedMethodInvocation <T, TResult> proxiedMethodInvocation, CachePolicy cachePolicy, TResult data)
        {
            var key          = proxiedMethodInvocation.GetHashString(_hashScramble);
            var cachedObject = new RedisObject <TResult>()
            {
                Created = DateTime.Now,
                Object  = data
            };

            var bytes = SerializeAndZip(cachedObject);

            if (cachePolicy.MaxAge > 0)
            {
                await _redis.Set(key, bytes, TimeSpan.FromSeconds(cachePolicy.MaxAge));
            }
            else
            {
                await _redis.Set(key, bytes);
            }
        }