Skip to content

Commit

Permalink
V15: Fix reload memory cache endpoint (#17446)
Browse files Browse the repository at this point in the history
* Check for id later.

* Return 501 status codes from obsoleted endpoints

* Use contants

* Ensure ordering of cache refresher is not changes

---------

Co-authored-by: Bjarke Berg <[email protected]>
  • Loading branch information
Zeegaan and bergmania authored Nov 7, 2024
1 parent e7eb14d commit d101829
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 14 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using Asp.Versioning;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Umbraco.Cms.Core.PublishedCache;

namespace Umbraco.Cms.Api.Management.Controllers.PublishedCache;

Expand All @@ -11,9 +10,9 @@ public class CollectPublishedCacheController : PublishedCacheControllerBase
{
[HttpPost("collect")]
[MapToApiVersion("1.0")]
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status501NotImplemented)]
public async Task<IActionResult> Collect(CancellationToken cancellationToken)
{
return Ok();
return StatusCode(StatusCodes.Status501NotImplemented);
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using Asp.Versioning;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Umbraco.Cms.Core.PublishedCache;

namespace Umbraco.Cms.Api.Management.Controllers.PublishedCache;

Expand All @@ -11,7 +10,9 @@ public class StatusPublishedCacheController : PublishedCacheControllerBase
{
[HttpGet("status")]
[MapToApiVersion("1.0")]
[ProducesResponseType(typeof(string), StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status501NotImplemented)]
public async Task<ActionResult<string>> Status(CancellationToken cancellationToken)
=> await Task.FromResult(Ok("Obsoleted"));
{
return StatusCode(StatusCodes.Status501NotImplemented);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -86,15 +86,16 @@ public override void Refresh(JsonPayload[] payloads)
var idsRemoved = new HashSet<int>();
IAppPolicyCache isolatedCache = AppCaches.IsolatedCaches.GetOrCreate<IContent>();

foreach (JsonPayload payload in payloads.Where(x => x.Id != default))
foreach (JsonPayload payload in payloads)
{
// By INT Id
isolatedCache.Clear(RepositoryCacheKeys.GetKey<IContent, int>(payload.Id));

// By GUID Key
isolatedCache.Clear(RepositoryCacheKeys.GetKey<IContent, Guid?>(payload.Key));

if (payload.Id != default)
{
// By INT Id
isolatedCache.Clear(RepositoryCacheKeys.GetKey<IContent, int>(payload.Id));

// By GUID Key
isolatedCache.Clear(RepositoryCacheKeys.GetKey<IContent, Guid?>(payload.Key));
}

// remove those that are in the branch
if (payload.ChangeTypes.HasTypesAny(TreeChangeTypes.RefreshBranch | TreeChangeTypes.Remove))
Expand All @@ -115,7 +116,10 @@ public override void Refresh(JsonPayload[] payloads)

HandleNavigation(payload);
HandlePublishedAsync(payload, CancellationToken.None).GetAwaiter().GetResult();
_idKeyMap.ClearCache(payload.Id);
if (payload.Id != default)
{
_idKeyMap.ClearCache(payload.Id);
}
if (payload.Key.HasValue)
{
_idKeyMap.ClearCache(payload.Key.Value);
Expand Down

0 comments on commit d101829

Please sign in to comment.