/// <summary> /// Used during serialization to compress properties /// </summary> /// <param name="content"></param> /// <param name="model"></param> /// <param name="published"></param> /// <remarks> /// This will essentially 'double compress' property data. The MsgPack data as a whole will already be compressed /// but this will go a step further and double compress property data so that it is stored in the nucache file /// as compressed bytes and therefore will exist in memory as compressed bytes. That is, until the bytes are /// read/decompressed as a string to be displayed on the front-end. This allows for potentially a significant /// memory savings but could also affect performance of first rendering pages while decompression occurs. /// </remarks> private void Compress(IReadOnlyContentBase content, ContentCacheDataModel model, bool published) { if (model.PropertyData is null) { return; } foreach (var propertyAliasToData in model.PropertyData) { if (_propertyOptions.IsCompressed(content, propertyAliasToData.Key, published)) { foreach (var property in propertyAliasToData.Value.Where(x => x.Value != null && x.Value is string)) { if (property.Value is string propertyValue) { property.Value = LZ4Pickler.Pickle(Encoding.UTF8.GetBytes(propertyValue), LZ4Level.L00_FAST); } } foreach (var property in propertyAliasToData.Value.Where(x => x.Value != null && x.Value is int intVal)) { property.Value = Convert.ToBoolean((int?)property.Value); } } } }
/// <summary> /// Used during serialization to compress properties /// </summary> /// <param name="model"></param> /// <remarks> /// This will essentially 'double compress' property data. The MsgPack data as a whole will already be compressed /// but this will go a step further and double compress property data so that it is stored in the nucache file /// as compressed bytes and therefore will exist in memory as compressed bytes. That is, until the bytes are /// read/decompressed as a string to be displayed on the front-end. This allows for potentially a significant /// memory savings but could also affect performance of first rendering pages while decompression occurs. /// </remarks> private void Compress(IReadOnlyContentBase content, ContentCacheDataModel model) { foreach (var propertyAliasToData in model.PropertyData) { if (_propertyOptions.IsCompressed(content, propertyAliasToData.Key)) { foreach (var property in propertyAliasToData.Value.Where(x => x.Value != null && x.Value is string)) { property.Value = LZ4Pickler.Pickle(Encoding.UTF8.GetBytes((string)property.Value), LZ4Level.L00_FAST); } } } }