I have a private method to publish an item to the Sitecore Web database programmatically. It's publishing the item to the Web database but not clearing the cache. I still see the data from the older version of the published item. I was under the impression that the Sitecore publishing module in Sitecore 9.3 version automatically clears the cache when the item is published.
Do I have to explicitly write a line of code to clear the cache or is there a better way to do this?
I did try to add this line but it did not work for me Sitecore.Caching.CacheManager.ClearAllCaches()
private void PublishItem(Sitecore.Data.Items.Item item)
{
PublishOptions publishOptions =
new PublishOptions(item.Database,
Database.GetDatabase("web"),
PublishMode.SingleItem,
item.Language,
DateTime.Now)
{
UserName = "sitecore\\admin"
};
Publisher publisher = new Publisher(publishOptions);
publisher.Options.RootItem = item;
publisher.Options.Deep = true;
publisher.PublishAsync();
item.Publishing.ClearPublishingCache();
}