statamic / ideas

💡Discussions on ideas and feature requests for Statamic
https://statamic.dev
31 stars 1 forks source link

Warm entries automatically after clearing them #977

Open stuartcusackie opened 1 year ago

stuartcusackie commented 1 year ago

It seems to me that the static cache should be automatically warmed again after it is cleared.

For example, if I make changes to my 'primary' nav then the entire static cache is cleared. Rules:

'rules' => [
  'navigation' => [
    'primary' => [
        'urls' => [
        '/*'
      ]
    ],

So now nothing is cached and the website is slow. I have to manually run static:warm but usually I am unaware when my clients make changes to the navs. The same applies to globals.

I think this should be done automatically after any entry's static cache is cleared. It might be complicated because we may want to queue the warming, so I guess this would have to be an optional feature.

Thanks.

ryanmitchell commented 1 year ago

How we tend to handle this is using a NavSaved listener, then Artisan::call('statamic:static:warm)

ryanmitchell commented 8 months ago

You can do this using the UrlInvalidated event: https://github.com/statamic/cms/pull/8902

stuartcusackie commented 8 months ago

Cool, I think I have a similar solution implemented, but I think this should be a core feature, maybe.

ryanmitchell commented 8 months ago

Going by the conversation around that issue and the one linked to it, I think this is the solution.

stuartcusackie commented 8 months ago

Thank you, I will try that out!

stuartcusackie commented 2 weeks ago

Your listener example here works perfectly. I made it a queueable listener due to the number of entries on my site. Thank you!