private CacheValue <T> RedisValueToCacheValue <T>(RedisValue redisValue) { if (!redisValue.HasValue) { return(CacheValue <T> .NoValue); } if (redisValue == _nullValue) { return(CacheValue <T> .Null); } try { var value = redisValue.ToValueOfType <T>(_options.Serializer); return(new CacheValue <T>(value, true)); } catch (Exception ex) { if (_logger.IsEnabled(LogLevel.Error)) { _logger.LogError(ex, "Unable to deserialize value {Value} to type {Type}", redisValue, typeof(T).FullName); } if (_options.ShouldThrowOnSerializationError) { throw; } return(CacheValue <T> .NoValue); } }
private async Task <CacheValue <T> > RedisValueToCacheValueAsync <T>(RedisValue redisValue) { if (!redisValue.HasValue) { return(CacheValue <T> .NoValue); } if (redisValue == _nullValue) { return(CacheValue <T> .Null); } try { var value = await redisValue.ToValueOfType <T>(_serializer).AnyContext(); return(new CacheValue <T>(value, true)); } catch (Exception ex) { _logger.Error(ex, "Unable to deserialize value \"{redisValue}\" to type {type}", redisValue, typeof(T).FullName); return(CacheValue <T> .NoValue); } }