Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ public override void OnActionExecuted(HttpActionExecutedContext actionExecutedCo
if (actionExecutedContext.Response != null && !actionExecutedContext.Response.IsSuccessStatusCode) return;
if (actionExecutedContext.ActionContext.Request.Method != HttpMethod.Post &&
actionExecutedContext.ActionContext.Request.Method != HttpMethod.Put &&
actionExecutedContext.ActionContext.Request.Method != HttpMethod.Delete) return;
actionExecutedContext.ActionContext.Request.Method != HttpMethod.Delete &&
actionExecutedContext.ActionContext.Request.Method.Method.ToLower() != "patch" &&
actionExecutedContext.ActionContext.Request.Method.Method.ToLower() != "merge") return;

var controller = actionExecutedContext.ActionContext.ControllerContext.ControllerDescriptor;
var actions = FindAllGetMethods(controller.ControllerType, TryMatchType ? actionExecutedContext.ActionContext.ActionDescriptor.GetParameters() : null);
Expand Down
17 changes: 12 additions & 5 deletions src/WebApi.OutputCache.V2/CacheOutputAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,17 @@ protected virtual MediaTypeHeaderValue GetExpectedMediaType(HttpConfiguration co
if (negotiator != null && returnType != typeof(HttpResponseMessage))
{
var negotiatedResult = negotiator.Negotiate(returnType, actionContext.Request, config.Formatters);
if (negotiatedResult != null)
{
responseMediaType = negotiatedResult.MediaType;
if (string.IsNullOrWhiteSpace(responseMediaType.CharSet))
{
responseMediaType.CharSet = Encoding.UTF8.HeaderName;
}
}
else
{
return DefaultMediaType;
}
}
else
Expand Down Expand Up @@ -145,7 +152,7 @@ private void OnActionExecuting(HttpActionContext actionContext)

if (actionContext.Request.Headers.IfNoneMatch != null)
{
var etag = _webApiCache.Get(cachekey + Constants.EtagKey) as string;
var etag = _webApiCache.Get<string>(cachekey + Constants.EtagKey);
if (etag != null)
{
if (actionContext.Request.Headers.IfNoneMatch.Any(x => x.Tag == etag))
Expand All @@ -159,16 +166,16 @@ private void OnActionExecuting(HttpActionContext actionContext)
}
}

var val = _webApiCache.Get(cachekey) as byte[];
var val = _webApiCache.Get<byte[]>(cachekey);
if (val == null) return;

var contenttype = _webApiCache.Get(cachekey + Constants.ContentTypeKey) as MediaTypeHeaderValue ?? new MediaTypeHeaderValue(cachekey.Split(new[] {':'},2)[1]);
var contenttype = _webApiCache.Get<MediaTypeHeaderValue>(cachekey + Constants.ContentTypeKey) ?? new MediaTypeHeaderValue(cachekey.Split(new[] { ':' }, 2)[1]);

actionContext.Response = actionContext.Request.CreateResponse();
actionContext.Response.Content = new ByteArrayContent(val);

actionContext.Response.Content.Headers.ContentType = contenttype;
var responseEtag = _webApiCache.Get(cachekey + Constants.EtagKey) as string;
var responseEtag = _webApiCache.Get<string>(cachekey + Constants.EtagKey);
if (responseEtag != null) SetEtag(actionContext.Response, responseEtag);

var cacheTime = CacheTimeQuery.Execute(DateTime.Now);
Expand Down Expand Up @@ -221,7 +228,7 @@ private async Task OnActionExecuted(HttpActionExecutedContext actionExecutedCont
ApplyCacheHeaders(actionExecutedContext.ActionContext.Response, cacheTime);
}

protected virtual void ApplyCacheHeaders(HttpResponseMessage response, CacheTime cacheTime)
private void ApplyCacheHeaders(HttpResponseMessage response, CacheTime cacheTime)
{
if (cacheTime.ClientTimeSpan > TimeSpan.Zero || MustRevalidate || Private)
{
Expand Down
2 changes: 1 addition & 1 deletion src/WebApi.OutputCache.V2/DefaultCacheKeyGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public class DefaultCacheKeyGenerator : ICacheKeyGenerator
{
public virtual string MakeCacheKey(HttpActionContext context, MediaTypeHeaderValue mediaType, bool excludeQueryString = false)
{
var controller = context.ControllerContext.ControllerDescriptor.ControllerName;
var controller = context.ControllerContext.ControllerDescriptor.ControllerType.FullName;
var action = context.ActionDescriptor.ActionName;
var key = context.Request.GetConfiguration().CacheOutputConfiguration().MakeBaseCachekey(controller, action);
var actionParameters = context.ActionArguments.Where(x => x.Value != null).Select(x => x.Key + "=" + GetValue(x.Value));
Expand Down