From 8d4b30140eee99feeeb6672c88dd5984cc18d5f0 Mon Sep 17 00:00:00 2001 From: sbwalker Date: Tue, 11 Mar 2025 11:48:43 -0400 Subject: [PATCH] rename Cache service to OutputCache --- .../OqtaneServiceCollectionExtensions.cs | 2 +- Oqtane.Client/Modules/Admin/Site/Index.razor | 4 +- .../Modules/Admin/SystemInfo/Index.razor | 4 +- .../Resources/Modules/Admin/Site/Index.resx | 2 +- .../Modules/Admin/SystemInfo/Index.resx | 5 +- Oqtane.Client/Services/CacheService.cs | 23 -------- ...CacheService.cs => IOutputCacheService.cs} | 4 +- Oqtane.Client/Services/OutputCacheService.cs | 23 ++++++++ Oqtane.Server/Controllers/CacheController.cs | 31 ---------- .../Controllers/EndpointController.cs | 56 +++++++++++++++++++ .../Controllers/OutputCacheController.cs | 30 ++++++++++ .../OqtaneServiceCollectionExtensions.cs | 2 +- ...{CacheService.cs => OutputCacheService.cs} | 8 +-- 13 files changed, 127 insertions(+), 67 deletions(-) delete mode 100644 Oqtane.Client/Services/CacheService.cs rename Oqtane.Client/Services/Interfaces/{ICacheService.cs => IOutputCacheService.cs} (72%) create mode 100644 Oqtane.Client/Services/OutputCacheService.cs delete mode 100644 Oqtane.Server/Controllers/CacheController.cs create mode 100644 Oqtane.Server/Controllers/EndpointController.cs create mode 100644 Oqtane.Server/Controllers/OutputCacheController.cs rename Oqtane.Server/Services/{CacheService.cs => OutputCacheService.cs} (74%) diff --git a/Oqtane.Client/Extensions/OqtaneServiceCollectionExtensions.cs b/Oqtane.Client/Extensions/OqtaneServiceCollectionExtensions.cs index 76389888..c5590d51 100644 --- a/Oqtane.Client/Extensions/OqtaneServiceCollectionExtensions.cs +++ b/Oqtane.Client/Extensions/OqtaneServiceCollectionExtensions.cs @@ -53,7 +53,7 @@ namespace Microsoft.Extensions.DependencyInjection services.AddScoped(); services.AddScoped(); services.AddScoped(); - services.AddScoped(); + services.AddScoped(); // providers services.AddScoped(); diff --git a/Oqtane.Client/Modules/Admin/Site/Index.razor b/Oqtane.Client/Modules/Admin/Site/Index.razor index d33bfb85..5333cd3b 100644 --- a/Oqtane.Client/Modules/Admin/Site/Index.razor +++ b/Oqtane.Client/Modules/Admin/Site/Index.razor @@ -14,7 +14,7 @@ @inject IStringLocalizer Localizer @inject INotificationService NotificationService @inject IStringLocalizer SharedLocalizer -@inject ICacheService CacheService +@inject IOutputCacheService CacheService @if (_initialized) { @@ -936,7 +936,7 @@ } private async Task EvictSitemapOutputCache() { - await CacheService.EvictOutputCacheByTag(Constants.SitemapOutputCacheTag); + await CacheService.EvictByTag(Constants.SitemapOutputCacheTag); AddModuleMessage(Localizer["Success.SiteMap.CacheEvicted"], MessageType.Success); } } diff --git a/Oqtane.Client/Modules/Admin/SystemInfo/Index.razor b/Oqtane.Client/Modules/Admin/SystemInfo/Index.razor index 8195b656..e7329d7a 100644 --- a/Oqtane.Client/Modules/Admin/SystemInfo/Index.razor +++ b/Oqtane.Client/Modules/Admin/SystemInfo/Index.razor @@ -153,8 +153,10 @@

  - @Localizer["Swagger"]  +

+ @Localizer["Swagger"]  + @Localizer["Endpoints"]
diff --git a/Oqtane.Client/Resources/Modules/Admin/Site/Index.resx b/Oqtane.Client/Resources/Modules/Admin/Site/Index.resx index f0d23f03..0127c7cc 100644 --- a/Oqtane.Client/Resources/Modules/Admin/Site/Index.resx +++ b/Oqtane.Client/Resources/Modules/Admin/Site/Index.resx @@ -445,6 +445,6 @@ Clear Cache - SiteMap Output Cache Evicted + Site Map Cache Cleared \ No newline at end of file diff --git a/Oqtane.Client/Resources/Modules/Admin/SystemInfo/Index.resx b/Oqtane.Client/Resources/Modules/Admin/SystemInfo/Index.resx index 6a2cafee..19bdf93a 100644 --- a/Oqtane.Client/Resources/Modules/Admin/SystemInfo/Index.resx +++ b/Oqtane.Client/Resources/Modules/Admin/SystemInfo/Index.resx @@ -118,7 +118,7 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - Access Swagger UI + Swagger UI Framework Version @@ -306,4 +306,7 @@ 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. + + API Endpoints + \ No newline at end of file diff --git a/Oqtane.Client/Services/CacheService.cs b/Oqtane.Client/Services/CacheService.cs deleted file mode 100644 index 4856b1e9..00000000 --- a/Oqtane.Client/Services/CacheService.cs +++ /dev/null @@ -1,23 +0,0 @@ -using System.Net.Http; -using System.Threading; -using System.Threading.Tasks; - -using Oqtane.Documentation; -using Oqtane.Shared; - -namespace Oqtane.Services -{ - /// - [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}"); - } - } -} diff --git a/Oqtane.Client/Services/Interfaces/ICacheService.cs b/Oqtane.Client/Services/Interfaces/IOutputCacheService.cs similarity index 72% rename from Oqtane.Client/Services/Interfaces/ICacheService.cs rename to Oqtane.Client/Services/Interfaces/IOutputCacheService.cs index 910cde25..08826146 100644 --- a/Oqtane.Client/Services/Interfaces/ICacheService.cs +++ b/Oqtane.Client/Services/Interfaces/IOutputCacheService.cs @@ -6,13 +6,13 @@ namespace Oqtane.Services /// /// Service to manage cache /// - public interface ICacheService + public interface IOutputCacheService { /// /// Evicts the output cache for a specific tag /// /// /// - Task EvictOutputCacheByTag(string tag, CancellationToken cancellationToken = default); + Task EvictByTag(string tag); } } diff --git a/Oqtane.Client/Services/OutputCacheService.cs b/Oqtane.Client/Services/OutputCacheService.cs new file mode 100644 index 00000000..40b43752 --- /dev/null +++ b/Oqtane.Client/Services/OutputCacheService.cs @@ -0,0 +1,23 @@ +using System.Net.Http; +using System.Threading; +using System.Threading.Tasks; + +using Oqtane.Documentation; +using Oqtane.Shared; + +namespace Oqtane.Services +{ + /// + [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}"); + } + } +} diff --git a/Oqtane.Server/Controllers/CacheController.cs b/Oqtane.Server/Controllers/CacheController.cs deleted file mode 100644 index e2d0ed08..00000000 --- a/Oqtane.Server/Controllers/CacheController.cs +++ /dev/null @@ -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//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); - } - } -} diff --git a/Oqtane.Server/Controllers/EndpointController.cs b/Oqtane.Server/Controllers/EndpointController.cs new file mode 100644 index 00000000..5fea4619 --- /dev/null +++ b/Oqtane.Server/Controllers/EndpointController.cs @@ -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 _endpointSources; + + public EndpointController(IEnumerable endpointSources) + { + _endpointSources = endpointSources; + } + + // GET api/ + [HttpGet] + [Authorize(Roles = RoleNames.Host)] + public ActionResult Get() + { + var endpoints = _endpointSources + .SelectMany(item => item.Endpoints) + .OfType(); + + var output = endpoints.Select( + item => + { + var controller = item.Metadata + .OfType() + .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().FirstOrDefault()?.HttpMethods?[0], + Route = $"/{item.RoutePattern.RawText.TrimStart('/')}", + Action = action, + ControllerMethod = controllerMethod + }; + } + ); + + return Json(output); + } + } +} diff --git a/Oqtane.Server/Controllers/OutputCacheController.cs b/Oqtane.Server/Controllers/OutputCacheController.cs new file mode 100644 index 00000000..59a8ab09 --- /dev/null +++ b/Oqtane.Server/Controllers/OutputCacheController.cs @@ -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//{tag} + [HttpDelete("{tag}")] + [Authorize(Roles = RoleNames.Admin)] + public async Task EvictByTag(string tag) + { + await _cacheService.EvictByTag(tag); + } + } +} diff --git a/Oqtane.Server/Extensions/OqtaneServiceCollectionExtensions.cs b/Oqtane.Server/Extensions/OqtaneServiceCollectionExtensions.cs index bf34816d..9b4b09e9 100644 --- a/Oqtane.Server/Extensions/OqtaneServiceCollectionExtensions.cs +++ b/Oqtane.Server/Extensions/OqtaneServiceCollectionExtensions.cs @@ -117,7 +117,7 @@ namespace Microsoft.Extensions.DependencyInjection // services services.AddTransient(); services.AddTransient(); - services.AddTransient(); + services.AddTransient(); // repositories services.AddTransient(); diff --git a/Oqtane.Server/Services/CacheService.cs b/Oqtane.Server/Services/OutputCacheService.cs similarity index 74% rename from Oqtane.Server/Services/CacheService.cs rename to Oqtane.Server/Services/OutputCacheService.cs index ed54d547..520c93b1 100644 --- a/Oqtane.Server/Services/CacheService.cs +++ b/Oqtane.Server/Services/OutputCacheService.cs @@ -12,24 +12,24 @@ using Oqtane.Shared; namespace Oqtane.Services { [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 ILogManager _logger; private readonly IHttpContextAccessor _accessor; - public ServerCacheService(IOutputCacheStore outputCacheStore, ILogManager logger, IHttpContextAccessor accessor) + public ServerOutputCacheService(IOutputCacheStore outputCacheStore, ILogManager logger, IHttpContextAccessor accessor) { _outputCacheStore = outputCacheStore; _logger = logger; _accessor = accessor; } - public async Task EvictOutputCacheByTag(string tag, CancellationToken cancellationToken = default) + public async Task EvictByTag(string tag) { 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); } else