diff --git a/src/Umbraco.Cms.ManagementApi/Controllers/PublishedCache/CollectPublishedCacheController.cs b/src/Umbraco.Cms.ManagementApi/Controllers/PublishedCache/CollectPublishedCacheController.cs new file mode 100644 index 0000000000..35bedf36f0 --- /dev/null +++ b/src/Umbraco.Cms.ManagementApi/Controllers/PublishedCache/CollectPublishedCacheController.cs @@ -0,0 +1,23 @@ +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Mvc; +using Umbraco.Cms.Core.PublishedCache; + +namespace Umbraco.Cms.ManagementApi.Controllers.PublishedCache; + +public class CollectPublishedCacheController : PublishedCacheControllerBase +{ + private readonly IPublishedSnapshotService _publishedSnapshotService; + + public CollectPublishedCacheController(IPublishedSnapshotService publishedSnapshotService) + => _publishedSnapshotService = publishedSnapshotService; + + [HttpPost("collect")] + [MapToApiVersion("1.0")] + [ProducesResponseType(StatusCodes.Status200OK)] + public async Task Collect() + { + GC.Collect(); + await _publishedSnapshotService.CollectAsync(); + return Ok(); + } +} diff --git a/src/Umbraco.Cms.ManagementApi/Controllers/PublishedCache/PublishedCacheControllerBase.cs b/src/Umbraco.Cms.ManagementApi/Controllers/PublishedCache/PublishedCacheControllerBase.cs new file mode 100644 index 0000000000..206266e872 --- /dev/null +++ b/src/Umbraco.Cms.ManagementApi/Controllers/PublishedCache/PublishedCacheControllerBase.cs @@ -0,0 +1,13 @@ +using Microsoft.AspNetCore.Mvc; +using NSwag.Annotations; +using Umbraco.New.Cms.Web.Common.Routing; + +namespace Umbraco.Cms.ManagementApi.Controllers.PublishedCache; + +[ApiVersion("1.0")] +[ApiController] +[BackOfficeRoute("api/v{version:apiVersion}/published-cache")] +[OpenApiTag("PublishedCache")] +public class PublishedCacheControllerBase : ManagementApiControllerBase +{ +} diff --git a/src/Umbraco.Cms.ManagementApi/Controllers/PublishedCache/RebuildPublishedCacheController.cs b/src/Umbraco.Cms.ManagementApi/Controllers/PublishedCache/RebuildPublishedCacheController.cs new file mode 100644 index 0000000000..85a6602a52 --- /dev/null +++ b/src/Umbraco.Cms.ManagementApi/Controllers/PublishedCache/RebuildPublishedCacheController.cs @@ -0,0 +1,22 @@ +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Mvc; +using Umbraco.Cms.Core.PublishedCache; + +namespace Umbraco.Cms.ManagementApi.Controllers.PublishedCache; + +public class RebuildPublishedCacheController : PublishedCacheControllerBase +{ + private readonly IPublishedSnapshotService _publishedSnapshotService; + + public RebuildPublishedCacheController(IPublishedSnapshotService publishedSnapshotService) + => _publishedSnapshotService = publishedSnapshotService; + + [HttpPost("rebuild")] + [MapToApiVersion("1.0")] + [ProducesResponseType(StatusCodes.Status200OK)] + public async Task Collect() + { + _publishedSnapshotService.Rebuild(); + return await Task.FromResult(Ok()); + } +} diff --git a/src/Umbraco.Cms.ManagementApi/Controllers/PublishedCache/ReloadPublishedCacheController.cs b/src/Umbraco.Cms.ManagementApi/Controllers/PublishedCache/ReloadPublishedCacheController.cs new file mode 100644 index 0000000000..f4237ef210 --- /dev/null +++ b/src/Umbraco.Cms.ManagementApi/Controllers/PublishedCache/ReloadPublishedCacheController.cs @@ -0,0 +1,23 @@ +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Mvc; +using Umbraco.Cms.Core.Cache; +using Umbraco.Extensions; + +namespace Umbraco.Cms.ManagementApi.Controllers.PublishedCache; + +public class ReloadPublishedCacheController : PublishedCacheControllerBase +{ + private readonly DistributedCache _distributedCache; + + public ReloadPublishedCacheController(DistributedCache distributedCache) => _distributedCache = distributedCache; + + [HttpPost("reload")] + [MapToApiVersion("1.0")] + [ProducesResponseType(StatusCodes.Status200OK)] + public async Task Reload() + { + _distributedCache.RefreshAllPublishedSnapshot(); + return await Task.FromResult(Ok()); + } +} + diff --git a/src/Umbraco.Cms.ManagementApi/Controllers/PublishedCache/StatusPublishedCacheController.cs b/src/Umbraco.Cms.ManagementApi/Controllers/PublishedCache/StatusPublishedCacheController.cs new file mode 100644 index 0000000000..26047b1291 --- /dev/null +++ b/src/Umbraco.Cms.ManagementApi/Controllers/PublishedCache/StatusPublishedCacheController.cs @@ -0,0 +1,19 @@ +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Mvc; +using Umbraco.Cms.Core.PublishedCache; + +namespace Umbraco.Cms.ManagementApi.Controllers.PublishedCache; + +public class StatusPublishedCacheController : PublishedCacheControllerBase +{ + private readonly IPublishedSnapshotStatus _publishedSnapshotStatus; + + public StatusPublishedCacheController(IPublishedSnapshotStatus publishedSnapshotStatus) + => _publishedSnapshotStatus = publishedSnapshotStatus; + + [HttpGet("status")] + [MapToApiVersion("1.0")] + [ProducesResponseType(typeof(string), StatusCodes.Status200OK)] + public async Task> Status() + => await Task.FromResult(Ok(_publishedSnapshotStatus.GetStatus())); +} diff --git a/src/Umbraco.Cms.ManagementApi/OpenApi.json b/src/Umbraco.Cms.ManagementApi/OpenApi.json index 9c5c335cb3..ed7d09b353 100644 --- a/src/Umbraco.Cms.ManagementApi/OpenApi.json +++ b/src/Umbraco.Cms.ManagementApi/OpenApi.json @@ -273,6 +273,65 @@ } } } + }, + "/umbraco/api/v1/published-cache/collect": { + "post": { + "tags": [ + "PublishedCache" + ], + "operationId": "CollectPublishedCache_Collect", + "responses": { + "200": { + "description": "" + } + } + } + }, + "/umbraco/api/v1/published-cache/rebuild": { + "post": { + "tags": [ + "PublishedCache" + ], + "operationId": "RebuildPublishedCache_Collect", + "responses": { + "200": { + "description": "" + } + } + } + }, + "/umbraco/api/v1/published-cache/reload": { + "post": { + "tags": [ + "PublishedCache" + ], + "operationId": "ReloadPublishedCache_Reload", + "responses": { + "200": { + "description": "" + } + } + } + }, + "/umbraco/api/v1/published-cache/status": { + "get": { + "tags": [ + "PublishedCache" + ], + "operationId": "StatusPublishedCache_Status", + "responses": { + "200": { + "description": "", + "content": { + "application/json": { + "schema": { + "type": "string" + } + } + } + } + } + } } }, "components": { @@ -574,6 +633,9 @@ { "name": "Server" }, + { + "name": "PublishedCache" + }, { "name": "Profiling" }, diff --git a/tests/Umbraco.Tests.Integration/NewBackoffice/OpenAPIContractTest.cs b/tests/Umbraco.Tests.Integration/NewBackoffice/OpenAPIContractTest.cs index de5fcc6b3b..7b7f20944b 100644 --- a/tests/Umbraco.Tests.Integration/NewBackoffice/OpenAPIContractTest.cs +++ b/tests/Umbraco.Tests.Integration/NewBackoffice/OpenAPIContractTest.cs @@ -28,7 +28,7 @@ public class OpenAPIContractTest : UmbracoTestServerTestBase [Test] public async Task Validate_OpenApi_Contract_is_implemented() { - string[] keysToIgnore = { "servers" }; + string[] keysToIgnore = { "servers", "x-generator" }; var officePath = GlobalSettings.GetBackOfficePath(HostingEnvironment);