Content Cache not updated
# help-with-umbraco
m
Hi All, In the Umbraco v14.3 site that I'm busy with, I get data from an API endpoint and and save it to a document. The problem I'm having is the IPublishedContent still has the old data when quering the document.
Copy code
// Get document from cache
_publishedContentQuery.Content(Constant.AvailablePricesDocumentGuid
)

//Logic to test if the data is still valid or must be updated

var doc = _ContentService.GetById(Constant.AvailablePricesDocumentGuid);

doc.SetValue("itemPrice", apiResponse.Price)

_contentService.Save(doc);
_contentService.Publish(doc,[]);
In the back office I can see the data is updated, but when refreshing the page it needs to display on has the old data and that's using IPublishedContentQuery. If i navigate to the back office and click on save and publish the content cache is updated and updated on the front end Any idea what i could be doing wrong? To my knowledge calling .Publish() should update the content cache, could be wrong. Any help would be appreciated. Thanks in advanced.
r
I think you should be able to do
_contentService.SaveAndPublish(doc)
, you may have a race condition where it's publishing the old content before saving the new values
m
Ok, thank you i will give that a try
I see that SaveAndPublish will not save, but only publish is this ok? looks like ir;s obsolete and will be removed in v16
s
r
Ah, my mistake, didn't realise it had been split out. I'm not sure what may be happening there then
44 Views