upper icon indicating copy to clipboard operation
upper copied to clipboard

Cache invalidation for scheduled Entries

Open ostark opened this issue 6 years ago • 16 comments

Problem: Scheduled Entries do not purge the cache automatically.

Idea

A console command keeps an eye on entries.postDate and entries. expiryDate. This command must be scheduled via cron to invalidated the cache without human interaction.

ostark avatar Oct 25 '17 15:10 ostark

We just discussed this on the Craft Slack.

For Craft 2 I did this plugin. For Craft 3, I think i'm going to port it and convert it into using delayed jobs instead.

sjelfull avatar Oct 25 '17 18:10 sjelfull

Perfect! @sjelfull

ostark avatar Oct 25 '17 19:10 ostark

So I’ve been thinking about this too, for Craft 2 I did a wider agnostic approach with Scheduler that does this but can also be extended to do anything else, like email someone a reminder in a week or whatever.

joshangell avatar Oct 26 '17 07:10 joshangell

The conceptual issue I’m having with delayed jobs in a queue is that what if the server gets rebooted or whatever, do they stay around? Can they be scheduled for a long time is the future, like a month or whatever?

I appreciated you could use SQS or whatever, but there’s something nice and safe about a row in a db.

joshangell avatar Oct 26 '17 07:10 joshangell

@joshangell thanks for your input. @sjelfull I'm not sure if delayed jobs are appropriate for this as you never get Jobs out of a queue, e.g. in case the editor decides to change the expire or publish date. Maybe this is not a big issue.

ostark avatar Oct 26 '17 15:10 ostark

@ostark Doesn't matter. You just publish a new job, and in the service you check if the entry is published/expired.

sjelfull avatar Oct 26 '17 16:10 sjelfull

Ok, @sjelfull, I'm happy to depend on your plugin 👍 Do you know if plugin-plugin dependencies are possible with Craft 3 anyways?

ostark avatar Oct 26 '17 19:10 ostark

Craft does not support it directly, but you can suggest/require your own dependencies, and they will be installed by composer.

sjelfull avatar Oct 26 '17 21:10 sjelfull

Pushed initial version in https://github.com/sjelfull/craft3-publishedevent

sjelfull avatar Oct 27 '17 08:10 sjelfull

In Upper 2.0

php craft upper/scheduled

Added https://github.com/ostark/upper/commit/29e4ec55125331b31573286bd6be46714f52813a

ostark avatar Jan 02 '19 23:01 ostark

In Upper 2.0

php craft upper/scheduled

Added 29e4ec5

I just found this, and it seems to solve a problem I've been having. I see it's been merged into develop. Any change of getting it into a minor release in the near future?

Or I guess an Upper 2 release.

RedLucas avatar Apr 08 '21 18:04 RedLucas

2.0 is a completely different code base. It's better than the 1.0 code, but also not completely happy - it's actually 2 years old. I'm looking forward to bring Upper to the next level this year.

ostark avatar Apr 08 '21 18:04 ostark

@ostark For expiryDate, I was thinking we should probably be able to handle it without a cron.

When we're listening for elements to add their tags, if they have an expiryDate, we could compare it to the default for the Cache-Control: max-age header. If it is sooner, we update the value for max-age.

timkelty avatar Sep 02 '22 14:09 timkelty

@timkelty what if we have a list with multiple elements?

ostark avatar Sep 07 '22 18:09 ostark

@ostark as it iterated through the elements, it would just update the soonest expiry date (if it was sooner than the default)

timkelty avatar Sep 07 '22 18:09 timkelty

@ostark Craft now does this natively for its own cache: https://github.com/craftcms/cms/pull/11901

timkelty avatar Sep 08 '22 07:09 timkelty