Browse Source

Added output cache to same parameters.

pull/282/head
Sebastian Stehle 8 years ago
parent
commit
c2de15d8a8
  1. 1
      src/Squidex/Areas/Api/Controllers/Assets/AssetContentController.cs
  2. 1
      src/Squidex/Areas/Api/Controllers/Users/UsersController.cs
  3. 38
      src/Squidex/Pipeline/ActionContextLogAppender.cs

1
src/Squidex/Areas/Api/Controllers/Assets/AssetContentController.cs

@ -60,6 +60,7 @@ namespace Squidex.Areas.Api.Controllers.Assets
[Route("assets/{id}/")] [Route("assets/{id}/")]
[ProducesResponseType(200)] [ProducesResponseType(200)]
[ApiCosts(0.5)] [ApiCosts(0.5)]
[ResponseCache(Duration = 3600, VaryByQueryKeys = new string[] { "version", "width", "height", "mode" })]
public async Task<IActionResult> GetAssetContent(string app, Guid id, [FromQuery] int version = -1, [FromQuery] int? width = null, [FromQuery] int? height = null, [FromQuery] string mode = null) public async Task<IActionResult> GetAssetContent(string app, Guid id, [FromQuery] int version = -1, [FromQuery] int? width = null, [FromQuery] int? height = null, [FromQuery] string mode = null)
{ {
var entity = await assetRepository.FindAssetAsync(id); var entity = await assetRepository.FindAssetAsync(id);

1
src/Squidex/Areas/Api/Controllers/Users/UsersController.cs

@ -139,6 +139,7 @@ namespace Squidex.Areas.Api.Controllers.Users
[HttpGet] [HttpGet]
[Route("users/{id}/picture/")] [Route("users/{id}/picture/")]
[ProducesResponseType(200)] [ProducesResponseType(200)]
[ResponseCache(Duration = 3600)]
public async Task<IActionResult> GetUserPicture(string id) public async Task<IActionResult> GetUserPicture(string id)
{ {
try try

38
src/Squidex/Pipeline/ActionContextLogAppender.cs

@ -6,32 +6,28 @@
// ========================================================================== // ==========================================================================
using System; using System;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc.Infrastructure; using Microsoft.AspNetCore.Mvc.Infrastructure;
using Squidex.Infrastructure.Log; using Squidex.Infrastructure.Log;
namespace Squidex.Pipeline namespace Squidex.Pipeline
{ {
public class ActionContextLogAppender : ILogAppender public sealed class ActionContextLogAppender : ILogAppender
{ {
private readonly IActionContextAccessor actionContextAccessor; private readonly IActionContextAccessor actionContextAccessor;
private readonly IHttpContextAccessor httpContextAccessor;
public ActionContextLogAppender(IActionContextAccessor actionContextAccessor) public ActionContextLogAppender(IActionContextAccessor actionContextAccessor, IHttpContextAccessor httpContextAccessor)
{ {
this.actionContextAccessor = actionContextAccessor; this.actionContextAccessor = actionContextAccessor;
this.httpContextAccessor = httpContextAccessor;
} }
public void Append(IObjectWriter writer) public void Append(IObjectWriter writer)
{ {
var actionContext = actionContextAccessor.ActionContext; var httpContext = httpContextAccessor.HttpContext;
if (actionContext == null)
{
return;
}
var httpContext = actionContext.HttpContext;
if (string.IsNullOrEmpty(httpContext.Request.Method)) if (string.IsNullOrEmpty(httpContext?.Request?.Method))
{ {
return; return;
} }
@ -47,17 +43,25 @@ namespace Squidex.Pipeline
httpContext.Items[nameof(requestId)] = requestId = Guid.NewGuid(); httpContext.Items[nameof(requestId)] = requestId = Guid.NewGuid();
} }
writer.WriteObject("web", w => w writer.WriteObject("web", w =>
.WriteProperty("requestId", requestId.ToString()) {
.WriteProperty("requestPath", httpContext.Request.Path) w.WriteProperty("requestId", requestId.ToString());
.WriteProperty("requestMethod", httpContext.Request.Method) w.WriteProperty("requestPath", httpContext.Request.Path);
.WriteObject("routeValues", r => w.WriteProperty("requestMethod", httpContext.Request.Method);
var actionContext = actionContextAccessor.ActionContext;
if (actionContext != null)
{
w.WriteObject("routeValues", r =>
{ {
foreach (var kvp in actionContext.ActionDescriptor.RouteValues) foreach (var kvp in actionContext.ActionDescriptor.RouteValues)
{ {
r.WriteProperty(kvp.Key, kvp.Value); r.WriteProperty(kvp.Key, kvp.Value);
} }
})); });
}
});
} }
} }
} }

Loading…
Cancel
Save