private T GetValue <T>(byte[] data) { if (data != null) { if (CacheUtil.IsGZipHeader(data)) { var unzip = CacheUtil.Decompress(data); return(CacheUtil.DeserializeProtobuf <T>(unzip)); } return(CacheUtil.DeserializeProtobuf <T>(data)); } return(default(T)); }
/// <summary> /// Adds the specified key and object to the cache. /// </summary> /// <param name="key">key</param> /// <param name="data">Data</param> /// <param name="cacheTime">Cache time in minutes</param> public void Set(string key, object data, int cacheTime) { if (data == null) { return; } byte[] bytes = CacheUtil.SerializeProtobuf(data); if (bytes.Length > MinByteCompress) { bytes = CacheUtil.Compress(bytes); } if (cacheTime > 0) { _database.StringSet(key, bytes, new TimeSpan(0, 0, 0, cacheTime, 0), When.Always, CommandFlags.FireAndForget); } else { _database.StringSet(key, bytes, null, When.Always, CommandFlags.FireAndForget); } }