Exemplo n.º 1
0
        /// <summary>
        /// 캐시에 저장된 <see cref="MongoCacheEntry"/>에서 원본 값을 추출합니다.
        /// </summary>
        /// <param name="entry"></param>
        /// <returns></returns>
        private static object DeserializeValue(MongoCacheEntry entry) {
            entry.ShouldNotBeNull("entry");

            byte[] value = entry.Value;

            if(value == null)
                return null;

            if(entry.IsCompressed)
                value = Compressor.Decompress(value);

            return Serializer.Deserialize(value);
        }
Exemplo n.º 2
0
        /// <summary>
        /// 객체를 캐시에 저장하기 위해, <see cref="MongoCacheEntry"/> 인스턴스로 빌드합니다.
        /// </summary>
        /// <param name="key"></param>
        /// <param name="value"></param>
        /// <returns></returns>
        private MongoCacheEntry SerializeValue(object key, object value) {
            var entry = new MongoCacheEntry(GetCacheId(key), null);

            var serialized = Serializer.Serialize(value);
            if(serialized.Length > CompressThreshold) {
                serialized = Compressor.Compress(serialized);
                entry.IsCompressed = true;
            }
            entry.Value = serialized;
            return entry;
        }