Skip to content

Commit

Permalink
Add NoCompression option to CacheInfo and [CacheResponse] to skip com…
Browse files Browse the repository at this point in the history
…pression for this response
  • Loading branch information
mythz committed Jul 4, 2016
1 parent 24f292e commit 2f7f85d
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
5 changes: 5 additions & 0 deletions src/ServiceStack/CacheInfo.cs
Expand Up @@ -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
Expand Down
10 changes: 9 additions & 1 deletion src/ServiceStack/CacheResponseAttribute.cs
Expand Up @@ -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;
Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -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)
Expand Down
5 changes: 4 additions & 1 deletion src/ServiceStack/HttpCacheFeature.cs
Expand Up @@ -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())
{
Expand Down

0 comments on commit 2f7f85d

Please sign in to comment.