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

[Error] Undefined array key "en" in FileCacher:155 when invalidating static cache of 2nd site with path /en #7411

Closed
jlmmns opened this issue Jan 26, 2023 · 18 comments · Fixed by #7509
Labels

Comments

@jlmmns
Copy link

jlmmns commented Jan 26, 2023

Bug description

I have a Multi-Site configuration running with Full Static Caching.
But the invalidation rules don't seem to work for my 2nd site.
Only the 1st site gets invalidated when saving an entry.

It might have to do with the path /en of the 2nd site. (#7403)

Error in the logs:

[2023-01-26 20:54:27] production.ERROR: Undefined array key "en" {"exception":"[object] (ErrorException(code: 0): Undefined array key \"en\" at /home/forge/site/vendor/statamic/cms/src/StaticCaching/Cachers/FileCacher.php:155

How to reproduce

/config/statamic/sites.php

'sites' => [

    'nl' => [
        'name' => "Nederlands",
        'locale' => 'nl_BE',
        'url' => env('APP_URL'),
    ],

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

],

/config/statamic/static_caching.php

'invalidation' => [

    'class' => null,

    'rules' => [
        'collections' => [
            'news' => [
                'urls' => [
                    '/nieuws',    // works
                    '/nieuws/*',  // works
                    '/en/news',   // not working
                    '/en/news/*', // not working
                    '/news',      // not working
                    '/news/*'     // not working
                ]
            ],
            ...

Logs

No response

Environment

Environment
Application Name: Statamic
Laravel Version: 9.45.1
PHP Version: 8.1.10
Composer Version: 2.5.1
Environment: production
Debug Mode: OFF
URL: example.com
Maintenance Mode: OFF

Cache
Config: NOT CACHED
Events: NOT CACHED
Routes: NOT CACHED
Views: NOT CACHED

Drivers
Broadcasting: log
Cache: redis
Database: mysql
Logs: stack / daily
Mail: smtp
Queue: redis
Session: file

Statamic
Addons: 0
Antlers: runtime
Stache Watcher: Disabled
Static Caching: full
Version: 3.3.63 PRO

Installation

Fresh statamic/statamic site via CLI

Antlers Parser

runtime (new)

Additional details

No response

@jasonvarga
Copy link
Member

Please show the strategies block of your static_caching.php config file.

@jlmmns
Copy link
Author

jlmmns commented Jan 26, 2023

Hey Jason!

Thanks for the very quick response!

Pretty sure I didn't touch the strategies block... ?

'strategies' => [

    'half' => [
        'driver' => 'application',
        'expiry' => null,
    ],

    'full' => [
        'driver' => 'file',
        'path' => public_path('static'),
        'lock_hold_length' => 0,
    ],

],

@edalzell
Copy link
Contributor

maybe related? #7403

@jlmmns
Copy link
Author

jlmmns commented Jan 27, 2023

I just noticed this error in the logs:

[2023-01-26 20:54:27] production.ERROR: Undefined array key "en" {"exception":"[object] (ErrorException(code: 0): Undefined array key \"en\" at /home/forge/site/vendor/statamic/cms/src/StaticCaching/Cachers/FileCacher.php:155

@jlmmns jlmmns changed the title [Multi-Site] Full Static Cache not cleared when entry gets saved for 2nd site [Error] Undefined array key "en" in FileCacher:155 when invalidating static cache of 2nd site with path /en Jan 27, 2023
@mnlmaier
Copy link
Contributor

mnlmaier commented Mar 20, 2023

Same issue here. I am trying to get Cache Invalidation in a multisite environment. Sometimes it's working, sometimes it's not... This error is also coming up occasionally.

@andjsch
Copy link
Contributor

andjsch commented Mar 23, 2023

I just noticed this error in the logs:

[2023-01-26 20:54:27] production.ERROR: Undefined array key "en" {"exception":"[object] (ErrorException(code: 0): Undefined array key \"en\" at /home/forge/site/vendor/statamic/cms/src/StaticCaching/Cachers/FileCacher.php:155

Experiencing the exact same error. I am using the DB queue driver. Not sure, but maybe it is related to that as well.

@jlmmns
Copy link
Author

jlmmns commented Mar 23, 2023

I just noticed this error in the logs:

[2023-01-26 20:54:27] production.ERROR: Undefined array key "en" {"exception":"[object] (ErrorException(code: 0): Undefined array key \"en\" at /home/forge/site/vendor/statamic/cms/src/StaticCaching/Cachers/FileCacher.php:155

Experiencing the exact same error. I am using the DB queue driver. Not sure, but maybe it is related to that as well.

Yeah, it really seems to have to do with the URL locale suffix/prefix.

@jasonvarga
Copy link
Member

Can you try to composer patch #7509 to see if it solves your issue?

https://rias.be/blog/using-composer-patches

@andjsch
Copy link
Contributor

andjsch commented Mar 26, 2023

That PR works for me. No more errors!

@mnlmaier
Copy link
Contributor

I currently have issues patching this in on Mac OS Ventura (related: cweagans/composer-patches#423, though unable to solve) which prevents me from locally testing this... @jasonvarga any chance that this might make it into the core? :)

@andjsch
Copy link
Contributor

andjsch commented Mar 27, 2023

@mnlmaier worst case if you really wanna try it: it's just two lines of code that have changed. You can update these lines inside the vendor folder.

1 similar comment
@andjsch
Copy link
Contributor

andjsch commented Mar 27, 2023

@mnlmaier worst case if you really wanna try it: it's just two lines of code that have changed. You can update these lines inside the vendor folder.

@mnlmaier
Copy link
Contributor

@AndreasSchantl sure, I almost would have done that, but it doesn't feel right editing vendor files on the client's production system were multiple people have the ability to deploy and potentially revert the change without me knowing – composer patching would at least make sure that additional deployments won't break things again :/

@andjsch
Copy link
Contributor

andjsch commented Mar 27, 2023

@AndreasSchantl sure, I almost would have done that, but it doesn't feel right editing vendor files on the client's production system were multiple people have the ability to deploy and potentially revert the change without me knowing – composer patching would at least make sure that additional deployments won't break things again :/

Of course – never do that in production! I was just talking about doing it locally to confirm that it works for you as well. I am sure it will be merged soon though!

@mnlmaier
Copy link
Contributor

mnlmaier commented Apr 3, 2023

Hi guys, any updates on this? It's sadly blocking core functionality for us...

@jlmmns
Copy link
Author

jlmmns commented Apr 3, 2023

@mnlmaier I temporarily "fixed" it with an event listener, whenever an entry gets saved, I reset the static cache. Not efficient at all, but it at least does the trick for now. 👍

@mnlmaier
Copy link
Contributor

mnlmaier commented Apr 3, 2023

@jlmmns I might have to make use of Event Listeners, too. Still feels not right having to do that if a fix seems to be available... :/

@jasonvarga
Copy link
Member

If you can confirm the PR fixes it for you, @mnlmaier we can get it into core.

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

Successfully merging a pull request may close this issue.

6 participants