<p>There isn't an event that fires when an entry with a future post date goes live, since it's just compared against the existing time and there's no guarantee that any PHP will be executing at that exact time.</p>

<p>You could write a cron job that hits a <a href="http://pluginfactory.io" rel="nofollow noreferrer">plugin's</a> controller that checks every minute or so for any entries about to go live.</p>

<p>Or maybe adopt something <a href="https://craftcms.stackexchange.com/questions/2610/how-can-i-cache-a-list-of-entries-with-pending-postdates-and-have-it-automatical">similar to this</a> for your Redis/full page caching solution.</p>

CC BY-SA 3.0
2016-11-15T21:33:22.280Z
Hmmm okay so since creating an entries.onPublish event would be so tricky, what about a process change. There is a draft [onPublish](https://craftcms.com/docs/plugins/events-reference#entryRevisions-onPublishDraft) event correct? Would I get the desired effect if the post and a draft containing the same content were scheduled to post at the same time? Kinda hacky, but...
Leah Scott
CC BY-SA 3.0
2016-11-15T21:44:01.580Z
Not sure I'm following 100%, but I don't think what you're thinking of will work. The easiest thing to me would probably be the cron job/plugin route.
Brad Bell
CC BY-SA 3.0
2016-11-15T22:12:40.303Z
Yeah, I agree that would be the simplest of the 2 solutions. I think considering the amount of work involved, I might opt for the even simpler solution of setting the Redis expire on this one page's key to 1 hour. Not perfect, but I'd rather not introduce another level of caching complexity. Thanks for your expertise as always :)
Leah Scott
CC BY-SA 3.0
2016-11-15T21:24:49.540Z
2016-11-15T21:24:49.540Z
Brad Bell
<p>I've created a plugin called <a href="https://superbig.co/plugins/published-event" rel="nofollow noreferrer">Published Event</a> does exactly what Brad suggests in his answer. It fires off an event when a entry moves from pending to live.</p>

CC BY-SA 3.0
2017-03-10T17:44:32.987Z
2017-03-10T17:44:32.987Z
Fred Carlsen
<p>For performance reasons I'm caching full HTML responses to Redis. This does wonders for response times, but cache invalidation becomes a bit tricky... I'm currently purging the entire cache on 'entries.saveEntry' which will suffice most of the time.</p>

<p>The problem is with scheduled posts. Scheduled posts are not saved when they're published so the cache is not invalidated and the post doesn't show up unless I clear the cache manually. I need to register 2 events listeners to clear the cache: one on entry save and one one on publish. Does this second event exist? If not, is there a way to create one?</p>

<plugin-development><cache><events>
Event Listener for Publishing Scheduled Posts
# Event Listener for Publishing Scheduled Posts

(Asked by: username_0 on 2016-11-15)

For performance reasons I'm caching full HTML responses to Redis. This does wonders for response times, but cache invalidation becomes a bit tricky... I'm currently purging the entire cache on 'entries.saveEntry' which will suffice most of the time.

The problem is with scheduled posts. Scheduled posts are not saved when they're published so the cache is not invalidated and the post doesn't show up unless I clear the cache manually. I need to register 2 events listeners to clear the cache: one on entry save and one one on publish. Does this second event exist? If not, is there a way to create one?

**Tags:** plugin-development, cache, events


---

## 2 answers

### Answer by username_1 on 2016-11-15. Score: 2 | Accepted answer

There isn't an event that fires when an entry with a future post date goes live, since it's just compared against the existing time and there's no guarantee that any PHP will be executing at that exact time.

You could write a cron job that hits a [plugin's](http://pluginfactory.io) controller that checks every minute or so for any entries about to go live.

Or maybe adopt something [similar to this](https://craftcms.stackexchange.com/questions/2610/how-can-i-cache-a-list-of-entries-with-pending-postdates-and-have-it-automatical) for your Redis/full page caching solution.

> **Comments:**
> **username_0**: Hmmm okay so since creating an entries.onPublish event would be so tricky, what about a process change. There is a draft [onPublish](https://craftcms.com/docs/plugins/events-reference#entryRevisions-onPublishDraft) event correct? Would I get the desired effect if the post and a draft containing the same content were scheduled to post at the same time? Kinda hacky, but...  
> **username_1**: Not sure I'm following 100%, but I don't think what you're thinking of will work. The easiest thing to me would probably be the cron job/plugin route.  
> **username_0**: Yeah, I agree that would be the simplest of the 2 solutions. I think considering the amount of work involved, I might opt for the even simpler solution of setting the Redis expire on this one page's key to 1 hour. Not perfect, but I'd rather not introduce another level of caching complexity. Thanks for your expertise as always :)  

---

### Answer by username_2 on 2017-03-10. Score: 1

I've created a plugin called [Published Event](https://superbig.co/plugins/published-event) does exactly what Brad suggests in his answer. It fires off an event when a entry moves from pending to live.


---

