Open adavidovic92 opened 4 weeks ago
Hi there @adavidovic92!
Firstly, a big thank you for raising this issue. Every piece of feedback we receive helps us to make Umbraco better.
We really appreciate your patience while we wait for our team to have a look at this but we wanted to let you know that we see this and share with you the plan for what comes next.
We wish we could work with everyone directly and assess your issue immediately but we're in the fortunate position of having lots of contributions to work with and only a few humans who are able to do it. We are making progress though and in the meantime, we will keep you in the loop and let you know when we have any questions.
Thanks, from your friendly Umbraco GitHub bot :robot: :slightly_smiling_face:
@adavidovic92 you can't rely on unpublished/published notifications, they can happen before nucache operations are finished, to get what you want working you need attach to cache refresher notification, check the whole thread here: https://github.com/umbraco/Umbraco-CMS/issues/13339
@bielu @nikolajlauridsen Unfortunately, I need to reopen this issue for several reasons, specifically regarding version 13.5.2
:
ContentCacheRefresherNotification
, it triggered before ContentPublishedNotification
. This implies that the content should already be updated in the cache by the time ContentPublishedNotification
fires.ContentPublishedNotification
to ContentCacheRefresherNotification
. However, it still re-caches the old content. This indicates that there is no clear notification to confirm when the Umbraco cache is fully updated, allowing the client to retrieve the latest data.ContentCacheRefresherNotification
sends a request to a simple Node.js server to retrieve the new data in Umbraco. However, in all 50 cases, the server received outdated content. Adding a 3-second delay on the Node.js server retrieves the latest data, but this appears to be the only workaround for now.In contrast, with version 13.3.2
, none of the above issues occur:
ContentPublishedNotification
fires, it successfully triggers a request to the client to retrieve the latest data, which works flawlessly.ContentPublishedNotification
consistently sends requests to the Node.js server, which receives the latest data in all cases.In summary, after upgrading from 13.3.2
to 13.5.2
, the client receives outdated data, and only by introducing a delay can the issue be resolved.
@adavidovic92 ContentCacheRefresherNotification can be randomly trigger before or after ContentPublishedNotification, which is documented, so you actually cant use ContentTreeChangeNotification either, but ContentCacheRefresherNotification (which is confusing as hell, but it what you need to do when using notifications). the only reliable notification is CCRN, not any related to content tree or content publishing.
@bielu Apologies for the confusion in my previous comment. I've corrected it now — I had originally used ContentCacheRefresherNotification
@adavidovic92 can you maybe share simplied version of your notitication handler? as it might be case of reusing previous umbraco context :)
public class ContentCacheRefresherNotificationHandler(ICustomClient customClient) : INotificationAsyncHandler<ContentCacheRefresherNotification>
{
public async Task HandleAsync(ContentCacheRefresherNotification notification, CancellationToken cancellationToken)
{
if (notification.MessageObject is not ContentCacheRefresher.JsonPayload[] payloads)
return;
foreach (ContentCacheRefresher.JsonPayload payload in payloads)
{
// Sends a request to a simple Node.js server to clear cache and retrieve the new data in Umbraco
await customClient.ClearCache();
}
return;
}
}
@adavidovic92 do you depend on Icontent? as I noticed you use Icontent service, to get fresh IPC you would need use
using (UmbracoContextReference context = _contextFactory.EnsureUmbracoContext())
{
IPublishedContent? published = context.UmbracoContext.Content?.GetById(payload.Id);
// Do stuff
}
If you want do that in you customClient you still can use factory :) also it might be issue with scopes, you might want create separate subscope in DI to ensure you dont share context with main event context, as than it would use stale version of IPC (There is a lot weird things with scoping and context in umbraco :))
@bielu You see, the content item might not need to be used at all. It is enough to simply send a request to the Node.js server to clear all cache and fetch new data. However, the issue is that it still receives outdated data.
@bielu In our context the content item is only used to construct the correct URL for the item that needs clearing — nothing more. The strange thing is that, within the customClient
, the content appears correct and seems updated. However, the server still receives outdated data, and we only get the latest data after setting a timeout. Interestingly, this issue does not occur with version 13.3.2.
@adavidovic92 do you any load balancing? as it might be loadbalacing issue not notification issue 🤔
@bielu No, we don't. This issue reproduces on a local machine with a clean Umbraco 13.5.2
project and does not occur with version 13.3.2
. Therefore, load balancing is not a factor.
@bielu https://github.com/umbraco/Umbraco-CMS/issues/17393#issuecomment-2462150764 All of this was done on a local machine.
@bielu This is a simple example of API endpoint for retrieving data which is used by Node.js server. Could the issue be related to publishedContentQuery
?
[Route("api/home")]
[ApiController]
[ApiExplorerSettings(GroupName = "Home")]
public class HomeController(IPublishedContentQuery publishedContentQuery) : ControllerBase
{
[HttpGet]
[ProducesResponseType(typeof(HomeRecord), StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status404NotFound)]
public Results<NotFound, Ok<HomeRecord>> Get()
{
var home = publishedContentQuery
.ContentAtRoot()
.OfType<Home>()
.FirstOrDefault();
if (home is null)
return TypedResults.NotFound();
return TypedResults.Ok(new HomeRecord(home.Title ?? string.Empty));
}
}
public record HomeRecord(string Title);
Tbh i never used IPublishedContentQuery as I found it hard to work with, so hard to say but I guess, could try wrap it with context factory and creating new context reference? or creating new snapshot wtih snapshot factory(I think it is how it was called)?
@bielu thank you, I will try to check this variant 👍
@bielu Unfortunately, I’ve tried both factories and accessors, but the result is the same—the client only receives old data. The data is only up-to-date if I set a timeout of 2-3 seconds.
Which Umbraco version are you using? (Please write the exact version, example: 10.1.0)
13.5.2
Bug summary
It was discovered that when attempting to unpublish, there is a delay during which the unpublished content remains accessible.
We have implemented a custom published/unpublished notification handler that sends a request to the client to clear its cache, followed by a new request to Umbraco to retrieve and cache the latest published content. However, due to a delay where unpublished content remains accessible, it re-caches the old content. This issue wasn’t present in the previous 13.3.2 version.
Specifics
No response
Steps to reproduce
The video below showcases a clean Umbraco solution with a simple API endpoint and a custom published notification handler that calls this API endpoint. However, the endpoint returns outdated data instead of the latest updates:
https://github.com/user-attachments/assets/42731550-81fa-4382-bd00-236bb578b65e
Expected result / actual result
When a custom published/unpublished notification handler is triggered the cache must be refreshed