Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refresh expired as soon as possible without queue #571

Closed
JodebaDigitalPulse opened this issue Oct 19, 2023 · 5 comments
Closed

Refresh expired as soon as possible without queue #571

JodebaDigitalPulse opened this issue Oct 19, 2023 · 5 comments
Labels
question Further information is requested

Comments

@JodebaDigitalPulse
Copy link

Hi,

I'm in search for the best way to refresh cache as soon as possible, for a website with high traffic.

So it brings me to these two refresh methods:

  • 2: Expire the cache and regenerate in a queue job
  • 0: Expire the cache, regenerate manually

We are now using method "2: Expire the cache and regenerate in a queue job", but the queue jobs keep stacking up. For example when saving the globals two times, two very long jobs are generating all pages. They are actually refreshing the same pages twice, at the same time, because we have multiple queue/listeners

So I was thinking of changing to method "0: Expire the cache, regenerate manually", but in the docs I can't find which cron job is supposed to run, I'm guessing blitz/cache/refresh-expired. But how can we make sure it is always running, without running twice or more at the same time.

I was hoping a 'listen' task could be started, so you could make a systemd service for it. An alternative is to start it every minute in a cron using flock, but in case of a crash, the lock will stay, and we want to be sure it is always running.

Thank you for your time!

Best regards,
Jonathan

@JodebaDigitalPulse JodebaDigitalPulse added the question Further information is requested label Oct 19, 2023
@JodebaDigitalPulse
Copy link
Author

Additionally:

When I run blitz/cache/refresh-expired, only the cached files are deleted, but not generated.
Because on RefreshCacheService.php#L536 there is no parameter $forceGenerate. In my case, I would want to create a cronjob that generates all the expired caches immediately, but there is no command to do this?

I can ofcourse create my own command, but I would think that $forceGenerate should be true for method "0: Expire the cache, regenerate manually"?

@bencroker
Copy link
Collaborator

bencroker commented Oct 19, 2023

Hi Jonathan. It sounds like Expire the cache and regenerate in a queue job is what you want. Globals should generally be avoided wherever possible as per https://putyourlightson.com/plugins/blitz#2-avoid-using-globals. You use cached includes for template partials that include elements and that are used in multiple pages, which should make a significant difference to the refresh cache process.

I can ofcourse create my own command, but I would think that $forceGenerate should be true for method "0: Expire the cache, regenerate manually"?

Maybe, I’ll have to look into that a bit closer.

@JodebaDigitalPulse
Copy link
Author

Thank you for your feedback!
You're right about the globals and cached includes, we are working towards it, but I was thinking about using the other method in the meantime.

@bencroker
Copy link
Collaborator

I’ve changed the behaviour in 7ef3507 to forcibly generate new cached pages if they are not cleared.

You can test this by running composer require "putyourlightson/craft-blitz:dev-develop as 4.6.1".

@bencroker
Copy link
Collaborator

Released in 4.7.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants