Closed mikesnoeren closed 6 days ago
Hi, thanks for getting in touch!
This is expected behaviour. As you said, the cache is invalidated when an entry is saved. If that entry happens to have a publish date that’s in the future, then it’ll show as having a “Pending” status and won’t be returned when you query for live entries. Then, when you query for the live entries again, and that post date turns out to be in the past, the entry is returned (and shows with a “Live” status), but no further saving is done to get to that place (nothing in the database changes).
There’s a StackExchange post that talks about how you can achieve what you’re after.
And then there’s this related discussion: https://github.com/craftcms/cms/discussions/9170.
I hope this helps!
I’ll close this now, but feel free to reply if you run into any further issues.
What happened?
Description
In our project, we have entries with a future post date, which are saved in a "pending" state until the post date passes. The issue is that the template cache doesn't clear when the entry is published (i.e., when the post date is reached), but only when the entry is saved initially (while in "pending" state).
Steps to reproduce
(Optional additional steps):
Expected behavior
The cache should be cleared when the entry is published (status changes to "live"), not when it's saved in the "pending" state.
Actual behavior
The cache is cleared when the entry is saved (while in "pending" state), not when it is published.
simplified code example
Craft CMS version
Craft Pro 4.12.6.1
PHP version
8.2.24
Operating system and version
Linux 6.11.5
Database type and version
MySQL 5.7.42
Image driver and version
GD 8.2.24
Installed plugins and versions