2

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?

2

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 controller that checks every minute or so for any entries about to go live.

Or maybe adopt something similar to this for your Redis/full page caching solution.

  • Hmmm okay so since creating an entries.onPublish event would be so tricky, what about a process change. There is a draft onPublish 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... – Liam Scott Nov 15 '16 at 21:33
  • 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 Nov 15 '16 at 21:44
  • 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 :) – Liam Scott Nov 15 '16 at 22:12
1

I've created a plugin called Published Event does exactly what Brad suggests in his answer. It fires off an event when a entry moves from pending to live.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.