Skip to content

Conversation

@arthurperton
Copy link
Contributor

@arthurperton arthurperton commented Sep 1, 2022

Fixes #3291. Fixes #6397.

Invalidating URLs in the static cache should work well now on multisite and when using async queues*. On multisite, when you update an entry, it will also invalidate the URLs of the descendants of that entry.

*When using with async queues, you must have your APP_URL set to the right value.

@arthurperton arthurperton marked this pull request as ready for review September 2, 2022 11:59
Copy link
Member

@jasonvarga jasonvarga left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is working well when it's the individual urls getting invalidated.
e.g. you save an entry, and that entry's url gets invalidated.

What's not working is when you have an array of 'urls' to invalidate from the config.

'invalidation' => [
  'rules' => [
    'collections' => [
      'blog' => [
        '/blog', // only does http://site1.com/blog. it won't invalidate `site2.com/blog`
      ],
    ],
  ],
]

Since you typically define relative the urls in the config, when it looks through, it doesn't pass along the domain.

This sorta thing:

$this->cacher->invalidateUrl(...$this->splitUrlAndDomain($url));

What we could probably do is in AbstractCacher@invalidateUrls, for each item, if they're not already an absolute URL, add the base url onto the start of it.

Then we can have support for invalidating multi-domain urls by telling people to define absolute urls in their config. That'd solve #6397.

'invalidation' => [
  'rules' => [
    'collections' => [
      'blog' => [
        '/blog', // assumes http://site1.com/blog
        'https://site2.com/blog', // since its defined absolute, we dont have to assume.
      ],
    ],
  ],
]

@arthurperton
Copy link
Contributor Author

Thanks, good point! I've been working on a fix, still have to add some tests later.

@arthurperton
Copy link
Contributor Author

Allright the AbstractCacher always passes a domain too now to ->invalidateUrl(). I also changed ->getBaseUrl() to make it more predictable and in line with what we want for multisite.

Tests were added for both ->invalidateUrls() and ->getBaseUrl().

@jasonvarga jasonvarga merged commit 5483e0f into statamic:3.3 Sep 13, 2022
@arthurperton arthurperton deleted the issue/issue-3291-static-cache-invalidate-queue branch September 13, 2022 16:37
@arthurperton
Copy link
Contributor Author

🎉

@stuartcusackie
Copy link

Still an issue on 3.3.67 I'm afraid.

@freshface
Copy link
Contributor

Yes, also on 3.4.7

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Static Caching invalidator not working when running from the queue Static cache not invalidated for multisite

4 participants