cms icon indicating copy to clipboard operation
cms copied to clipboard

Cache is not getting invalidated in Multisite setup

Open stefankempf opened this issue 2 years ago • 4 comments

Bug description

I'm having issues to invalidate the cache for two of my multisite installations. Whenever I save a field inside that global, no page is getting invalidated.

How to reproduce

In static_caching.php, I have tried multiple configs like the following, but none were working:

'globals' => [
    'brand' => [
        'urls' => [
            '/*',
        ]
    ],

or

'globals' => [
    'brand' => [
        'urls' => [
            '*',
        ]
    ],

or

'globals' => [
    'brand' => [
        'urls' => [
            env('APP_URL') . '/*',
        ]
    ],

and even hardcoded the url like so:

'globals' => [
    'brand' => [
        'urls' => [
            'http://domain.test/*',
        ]
    ],

My sites.php looks like this:

'sites' => [

    'de' => [
        'name' => 'Deutsch',
        'locale' => 'de_CH',
        'url' => env('APP_URL') . 'de/'
    ],

    'en' => [
        'name' => 'English',
        'locale' => 'en_GB',
        'url' => env('APP_URL') . 'en/'
    ],
    
],

and in my .env, I set the following: APP_URL=http://domain.test/

Logs

No log messages are getting generated when saving the mentioned global.

Environment

Statamic 3.4.5 Pro
Laravel 8.83.27
PHP 8.2.3
Stache Watcher Disabled
Static Caching half
appswithlove/statamic-one-click-content-translation 3.4.0

Installation

Fresh statamic/statamic site via CLI

Antlers Parser

runtime (new)

Additional details

No response

stefankempf avatar Mar 13 '23 20:03 stefankempf

btw: I also couldn't invalidate single pages as explained in the docs: https://statamic.dev/static-caching#when-saving

I needed to work around that issue like this:

'collections' => [
    'news' => [
        'urls' => [
            env('APP_URL') . 'de/news',
            env('APP_URL') . 'en/news',
        ]
    ]

stefankempf avatar Mar 14 '23 08:03 stefankempf

I've had this problem for the best part of a year (see here).

I can see cache invalidation jobs are being fired through horizon but my subsite caches don't get cleared properly.

stefankempf's workaround seems to fix it. Here's the workaround for my localised domains (see my original issue for my full sites configuration):

'rules' => [
  'collections' => [
     'blog' => [
      'urls' => [
        config('app.url') . '/blog',
        config('app.url_uk') . '/blog',
        config('app.url_com') . '/blog'
      ]
     ..... lots more rules

stuartcusackie avatar Mar 27 '23 10:03 stuartcusackie

Its an old one but ... Do you have paths set in config/statamic/static_caching.php (https://statamic.dev/static-caching#multisite)? IIRC it is required for static cache to be invalidated properly when on multisite.

Krzemo avatar Sep 11 '23 21:09 Krzemo

I haven't set paths but I don't use multiple domains in my projects and I also "only" use half measure, where I don't see any option to set paths and as far as I know, the files don't get rendered into the static storage folder. Is that a wrong assumption?

stefankempf avatar Sep 12 '23 08:09 stefankempf

I haven't set paths but I don't use multiple domains in my projects and I also "only" use half measure, where I don't see any option to set paths and as far as I know, the files don't get rendered into the static storage folder. Is that a wrong assumption?

I don't think paths apply to half-measure caching, but I am curious to see if using full-measure will circumvent the problem.

UPDATE: Full-measure static caching suffers the same problem.

stuartcusackie avatar Feb 19 '25 15:02 stuartcusackie