rename Cache service to OutputCache
This commit is contained in:
parent
70a3fab1ff
commit
8d4b30140e
|
@ -53,7 +53,7 @@ namespace Microsoft.Extensions.DependencyInjection
|
||||||
services.AddScoped<ISyncService, SyncService>();
|
services.AddScoped<ISyncService, SyncService>();
|
||||||
services.AddScoped<ILocalizationCookieService, LocalizationCookieService>();
|
services.AddScoped<ILocalizationCookieService, LocalizationCookieService>();
|
||||||
services.AddScoped<ICookieConsentService, CookieConsentService>();
|
services.AddScoped<ICookieConsentService, CookieConsentService>();
|
||||||
services.AddScoped<ICacheService, CacheService>();
|
services.AddScoped<IOutputCacheService, OutputCacheService>();
|
||||||
|
|
||||||
// providers
|
// providers
|
||||||
services.AddScoped<ITextEditor, Oqtane.Modules.Controls.QuillJSTextEditor>();
|
services.AddScoped<ITextEditor, Oqtane.Modules.Controls.QuillJSTextEditor>();
|
||||||
|
|
|
@ -14,7 +14,7 @@
|
||||||
@inject IStringLocalizer<Index> Localizer
|
@inject IStringLocalizer<Index> Localizer
|
||||||
@inject INotificationService NotificationService
|
@inject INotificationService NotificationService
|
||||||
@inject IStringLocalizer<SharedResources> SharedLocalizer
|
@inject IStringLocalizer<SharedResources> SharedLocalizer
|
||||||
@inject ICacheService CacheService
|
@inject IOutputCacheService CacheService
|
||||||
|
|
||||||
@if (_initialized)
|
@if (_initialized)
|
||||||
{
|
{
|
||||||
|
@ -936,7 +936,7 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task EvictSitemapOutputCache() {
|
private async Task EvictSitemapOutputCache() {
|
||||||
await CacheService.EvictOutputCacheByTag(Constants.SitemapOutputCacheTag);
|
await CacheService.EvictByTag(Constants.SitemapOutputCacheTag);
|
||||||
AddModuleMessage(Localizer["Success.SiteMap.CacheEvicted"], MessageType.Success);
|
AddModuleMessage(Localizer["Success.SiteMap.CacheEvicted"], MessageType.Success);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -153,8 +153,10 @@
|
||||||
</div>
|
</div>
|
||||||
<br /><br />
|
<br /><br />
|
||||||
<button type="button" class="btn btn-success" @onclick="SaveConfig">@SharedLocalizer["Save"]</button>
|
<button type="button" class="btn btn-success" @onclick="SaveConfig">@SharedLocalizer["Save"]</button>
|
||||||
<a class="btn btn-primary" href="swagger/index.html" target="_new">@Localizer["Swagger"]</a>
|
|
||||||
<ActionDialog Header="Restart Application" Message="Are You Sure You Wish To Restart The Application?" Action="Restart Application" Security="SecurityAccessLevel.Host" Class="btn btn-danger" OnClick="@(async () => await RestartApplication())" ResourceKey="RestartApplication" />
|
<ActionDialog Header="Restart Application" Message="Are You Sure You Wish To Restart The Application?" Action="Restart Application" Security="SecurityAccessLevel.Host" Class="btn btn-danger" OnClick="@(async () => await RestartApplication())" ResourceKey="RestartApplication" />
|
||||||
|
<br /><br />
|
||||||
|
<a class="btn btn-secondary" href="swagger/index.html" target="_new">@Localizer["Swagger"]</a>
|
||||||
|
<a class="btn btn-secondary" href="api/endpoint" target="_new">@Localizer["Endpoints"]</a>
|
||||||
</TabPanel>
|
</TabPanel>
|
||||||
<TabPanel Name="Log" Heading="Log" ResourceKey="Log">
|
<TabPanel Name="Log" Heading="Log" ResourceKey="Log">
|
||||||
<div class="container">
|
<div class="container">
|
||||||
|
|
|
@ -445,6 +445,6 @@
|
||||||
<value>Clear Cache</value>
|
<value>Clear Cache</value>
|
||||||
</data>
|
</data>
|
||||||
<data name="Success.SiteMap.CacheEvicted" xml:space="preserve">
|
<data name="Success.SiteMap.CacheEvicted" xml:space="preserve">
|
||||||
<value>SiteMap Output Cache Evicted</value>
|
<value>Site Map Cache Cleared</value>
|
||||||
</data>
|
</data>
|
||||||
</root>
|
</root>
|
|
@ -118,7 +118,7 @@
|
||||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||||
</resheader>
|
</resheader>
|
||||||
<data name="Swagger" xml:space="preserve">
|
<data name="Swagger" xml:space="preserve">
|
||||||
<value>Access Swagger UI</value>
|
<value>Swagger UI</value>
|
||||||
</data>
|
</data>
|
||||||
<data name="FrameworkVersion.HelpText" xml:space="preserve">
|
<data name="FrameworkVersion.HelpText" xml:space="preserve">
|
||||||
<value>Framework Version</value>
|
<value>Framework Version</value>
|
||||||
|
@ -306,4 +306,7 @@
|
||||||
<data name="CacheControl.HelpText" xml:space="preserve">
|
<data name="CacheControl.HelpText" xml:space="preserve">
|
||||||
<value>Provide a Cache-Control directive for static assets. For example 'public, max-age=60' indicates that static assets should be cached for 60 seconds. A blank value indicates caching is not enabled.</value>
|
<value>Provide a Cache-Control directive for static assets. For example 'public, max-age=60' indicates that static assets should be cached for 60 seconds. A blank value indicates caching is not enabled.</value>
|
||||||
</data>
|
</data>
|
||||||
|
<data name="Endpoints" xml:space="preserve">
|
||||||
|
<value>API Endpoints</value>
|
||||||
|
</data>
|
||||||
</root>
|
</root>
|
|
@ -1,23 +0,0 @@
|
||||||
using System.Net.Http;
|
|
||||||
using System.Threading;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
using Oqtane.Documentation;
|
|
||||||
using Oqtane.Shared;
|
|
||||||
|
|
||||||
namespace Oqtane.Services
|
|
||||||
{
|
|
||||||
/// <inheritdoc cref="ICacheService" />
|
|
||||||
[PrivateApi("Don't show in the documentation, as everything should use the Interface")]
|
|
||||||
public class CacheService : ServiceBase, ICacheService
|
|
||||||
{
|
|
||||||
public CacheService(HttpClient http, SiteState siteState) : base(http, siteState) { }
|
|
||||||
|
|
||||||
private string ApiUrl => CreateApiUrl("Cache");
|
|
||||||
|
|
||||||
public async Task EvictOutputCacheByTag(string tag, CancellationToken cancellationToken = default)
|
|
||||||
{
|
|
||||||
await DeleteAsync($"{ApiUrl}/outputCache/evictByTag/{tag}");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -6,13 +6,13 @@ namespace Oqtane.Services
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Service to manage cache
|
/// Service to manage cache
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public interface ICacheService
|
public interface IOutputCacheService
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Evicts the output cache for a specific tag
|
/// Evicts the output cache for a specific tag
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="tag"></param>
|
/// <param name="tag"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
Task EvictOutputCacheByTag(string tag, CancellationToken cancellationToken = default);
|
Task EvictByTag(string tag);
|
||||||
}
|
}
|
||||||
}
|
}
|
23
Oqtane.Client/Services/OutputCacheService.cs
Normal file
23
Oqtane.Client/Services/OutputCacheService.cs
Normal file
|
@ -0,0 +1,23 @@
|
||||||
|
using System.Net.Http;
|
||||||
|
using System.Threading;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
using Oqtane.Documentation;
|
||||||
|
using Oqtane.Shared;
|
||||||
|
|
||||||
|
namespace Oqtane.Services
|
||||||
|
{
|
||||||
|
/// <inheritdoc cref="IOutputCacheService" />
|
||||||
|
[PrivateApi("Don't show in the documentation, as everything should use the Interface")]
|
||||||
|
public class OutputCacheService : ServiceBase, IOutputCacheService
|
||||||
|
{
|
||||||
|
public OutputCacheService(HttpClient http, SiteState siteState) : base(http, siteState) { }
|
||||||
|
|
||||||
|
private string ApiUrl => CreateApiUrl("OutputCache");
|
||||||
|
|
||||||
|
public async Task EvictByTag(string tag)
|
||||||
|
{
|
||||||
|
await DeleteAsync($"{ApiUrl}/{tag}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,31 +0,0 @@
|
||||||
using System.Threading;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
using Microsoft.AspNetCore.Authorization;
|
|
||||||
using Microsoft.AspNetCore.Mvc;
|
|
||||||
|
|
||||||
using Oqtane.Models;
|
|
||||||
using Oqtane.Services;
|
|
||||||
using Oqtane.Shared;
|
|
||||||
|
|
||||||
namespace Oqtane.Controllers
|
|
||||||
{
|
|
||||||
[Route(ControllerRoutes.ApiRoute)]
|
|
||||||
public class CacheController : Controller
|
|
||||||
{
|
|
||||||
private readonly ICacheService _cacheService;
|
|
||||||
|
|
||||||
public CacheController(ICacheService cacheService)
|
|
||||||
{
|
|
||||||
_cacheService = cacheService;
|
|
||||||
}
|
|
||||||
|
|
||||||
// DELETE api/<controller>/outputCache/evictByTag/{tag}
|
|
||||||
[HttpDelete("outputCache/evictByTag/{tag}")]
|
|
||||||
[Authorize(Roles = RoleNames.Admin)]
|
|
||||||
public async Task EvictOutputCacheByTag(string tag, CancellationToken cancellationToken = default)
|
|
||||||
{
|
|
||||||
await _cacheService.EvictOutputCacheByTag(tag, cancellationToken);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
56
Oqtane.Server/Controllers/EndpointController.cs
Normal file
56
Oqtane.Server/Controllers/EndpointController.cs
Normal file
|
@ -0,0 +1,56 @@
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using Microsoft.AspNetCore.Authorization;
|
||||||
|
using Oqtane.Models;
|
||||||
|
using Oqtane.Shared;
|
||||||
|
using System.Linq;
|
||||||
|
using Microsoft.AspNetCore.Mvc.Controllers;
|
||||||
|
using Microsoft.AspNetCore.Routing;
|
||||||
|
|
||||||
|
namespace Oqtane.Controllers
|
||||||
|
{
|
||||||
|
[Route(ControllerRoutes.ApiRoute)]
|
||||||
|
public class EndpointController : Controller
|
||||||
|
{
|
||||||
|
private readonly IEnumerable<EndpointDataSource> _endpointSources;
|
||||||
|
|
||||||
|
public EndpointController(IEnumerable<EndpointDataSource> endpointSources)
|
||||||
|
{
|
||||||
|
_endpointSources = endpointSources;
|
||||||
|
}
|
||||||
|
|
||||||
|
// GET api/<controller>
|
||||||
|
[HttpGet]
|
||||||
|
[Authorize(Roles = RoleNames.Host)]
|
||||||
|
public ActionResult Get()
|
||||||
|
{
|
||||||
|
var endpoints = _endpointSources
|
||||||
|
.SelectMany(item => item.Endpoints)
|
||||||
|
.OfType<RouteEndpoint>();
|
||||||
|
|
||||||
|
var output = endpoints.Select(
|
||||||
|
item =>
|
||||||
|
{
|
||||||
|
var controller = item.Metadata
|
||||||
|
.OfType<ControllerActionDescriptor>()
|
||||||
|
.FirstOrDefault();
|
||||||
|
var action = controller != null
|
||||||
|
? $"{controller.ControllerName}.{controller.ActionName}"
|
||||||
|
: null;
|
||||||
|
var controllerMethod = controller != null
|
||||||
|
? $"{controller.ControllerTypeInfo.FullName}:{controller.MethodInfo.Name}"
|
||||||
|
: null;
|
||||||
|
return new
|
||||||
|
{
|
||||||
|
Method = item.Metadata.OfType<HttpMethodMetadata>().FirstOrDefault()?.HttpMethods?[0],
|
||||||
|
Route = $"/{item.RoutePattern.RawText.TrimStart('/')}",
|
||||||
|
Action = action,
|
||||||
|
ControllerMethod = controllerMethod
|
||||||
|
};
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
return Json(output);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
30
Oqtane.Server/Controllers/OutputCacheController.cs
Normal file
30
Oqtane.Server/Controllers/OutputCacheController.cs
Normal file
|
@ -0,0 +1,30 @@
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
using Microsoft.AspNetCore.Authorization;
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
|
||||||
|
using Oqtane.Models;
|
||||||
|
using Oqtane.Services;
|
||||||
|
using Oqtane.Shared;
|
||||||
|
|
||||||
|
namespace Oqtane.Controllers
|
||||||
|
{
|
||||||
|
[Route(ControllerRoutes.ApiRoute)]
|
||||||
|
public class OutputCacheController : Controller
|
||||||
|
{
|
||||||
|
private readonly IOutputCacheService _cacheService;
|
||||||
|
|
||||||
|
public OutputCacheController(IOutputCacheService cacheService)
|
||||||
|
{
|
||||||
|
_cacheService = cacheService;
|
||||||
|
}
|
||||||
|
|
||||||
|
// DELETE api/<controller>/{tag}
|
||||||
|
[HttpDelete("{tag}")]
|
||||||
|
[Authorize(Roles = RoleNames.Admin)]
|
||||||
|
public async Task EvictByTag(string tag)
|
||||||
|
{
|
||||||
|
await _cacheService.EvictByTag(tag);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -117,7 +117,7 @@ namespace Microsoft.Extensions.DependencyInjection
|
||||||
// services
|
// services
|
||||||
services.AddTransient<ISiteService, ServerSiteService>();
|
services.AddTransient<ISiteService, ServerSiteService>();
|
||||||
services.AddTransient<ILocalizationCookieService, ServerLocalizationCookieService>();
|
services.AddTransient<ILocalizationCookieService, ServerLocalizationCookieService>();
|
||||||
services.AddTransient<ICacheService, ServerCacheService>();
|
services.AddTransient<IOutputCacheService, ServerOutputCacheService>();
|
||||||
|
|
||||||
// repositories
|
// repositories
|
||||||
services.AddTransient<IModuleDefinitionRepository, ModuleDefinitionRepository>();
|
services.AddTransient<IModuleDefinitionRepository, ModuleDefinitionRepository>();
|
||||||
|
|
|
@ -12,24 +12,24 @@ using Oqtane.Shared;
|
||||||
namespace Oqtane.Services
|
namespace Oqtane.Services
|
||||||
{
|
{
|
||||||
[PrivateApi("Don't show in the documentation, as everything should use the Interface")]
|
[PrivateApi("Don't show in the documentation, as everything should use the Interface")]
|
||||||
public class ServerCacheService : ICacheService
|
public class ServerOutputCacheService : IOutputCacheService
|
||||||
{
|
{
|
||||||
private readonly IOutputCacheStore _outputCacheStore;
|
private readonly IOutputCacheStore _outputCacheStore;
|
||||||
private readonly ILogManager _logger;
|
private readonly ILogManager _logger;
|
||||||
private readonly IHttpContextAccessor _accessor;
|
private readonly IHttpContextAccessor _accessor;
|
||||||
|
|
||||||
public ServerCacheService(IOutputCacheStore outputCacheStore, ILogManager logger, IHttpContextAccessor accessor)
|
public ServerOutputCacheService(IOutputCacheStore outputCacheStore, ILogManager logger, IHttpContextAccessor accessor)
|
||||||
{
|
{
|
||||||
_outputCacheStore = outputCacheStore;
|
_outputCacheStore = outputCacheStore;
|
||||||
_logger = logger;
|
_logger = logger;
|
||||||
_accessor = accessor;
|
_accessor = accessor;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task EvictOutputCacheByTag(string tag, CancellationToken cancellationToken = default)
|
public async Task EvictByTag(string tag)
|
||||||
{
|
{
|
||||||
if (_accessor.HttpContext.User.IsInRole(RoleNames.Admin))
|
if (_accessor.HttpContext.User.IsInRole(RoleNames.Admin))
|
||||||
{
|
{
|
||||||
await _outputCacheStore.EvictByTagAsync(tag, cancellationToken);
|
await _outputCacheStore.EvictByTagAsync(tag, default);
|
||||||
_logger.Log(LogLevel.Information, this, LogFunction.Other, "Evicted Output Cache for Tag {Tag}", tag);
|
_logger.Log(LogLevel.Information, this, LogFunction.Other, "Evicted Output Cache for Tag {Tag}", tag);
|
||||||
}
|
}
|
||||||
else
|
else
|
Loading…
Reference in New Issue
Block a user