Skip to content
Permalink
Browse files

Add NoCompression option to CacheInfo and [CacheResponse] to skip com…

…pression for this response
  • Loading branch information...
mythz committed Jul 4, 2016
1 parent 24f292e commit 2f7f85dfd8489b32ad3305a4ddd3df7cc0fef1f6
@@ -61,6 +61,11 @@ public string CacheKey
/// Use HostContext.LocalCache or HostContext.Cache
/// </summary>
public bool LocalCache { get; set; }

/// <summary>
/// Skip compression for this Cache Result
/// </summary>
public bool NoCompression { get; set; }
}

public static class CacheInfoExtensions
@@ -39,6 +39,11 @@ public class CacheResponseAttribute : RequestFilterAttribute
/// </summary>
public bool LocalCache { get; set; }

/// <summary>
/// Skip compression for this Cache Result
/// </summary>
public bool NoCompression { get; set; }

public CacheResponseAttribute()
{
MaxAge = -1;
@@ -98,6 +103,7 @@ public override void Execute(IRequest req, IResponse res, object requestDto)
CacheControl = CacheControl,
VaryByUser = VaryByUser,
LocalCache = LocalCache,
NoCompression = NoCompression,
};

if (req.HandleValidCache(cacheInfo))
@@ -135,7 +141,9 @@ public static bool HandleValidCache(this IRequest req, CacheInfo cacheInfo)
}
}

var encoding = req.GetCompressionType();
var encoding = !cacheInfo.NoCompression
? req.GetCompressionType()
: null;

var responseBytes = encoding != null
? cache.Get<byte[]>(cacheInfo.CacheKey + "." + encoding)
@@ -100,7 +100,10 @@ private bool CacheAndWriteResponse(CacheInfo cacheInfo, IRequest req, IResponse
}
}

var encoding = req.GetCompressionType();
var encoding = !cacheInfo.NoCompression
? req.GetCompressionType()
: null;

var cacheKeyEncoded = encoding != null ? cacheInfo.CacheKey + "." + encoding : null;
if (responseBytes != null || req.ResponseContentType.IsBinary())
{

0 comments on commit 2f7f85d

Please sign in to comment.
You can’t perform that action at this time.