Description
Bug Description
The static cache file not removed when the queue is run through php artisan queue:work, (or using database queue).
After hours of inspection, the is due to the caching of full URL in the cache:
the problem is in /cms/src/StaticCaching/Cachers/FileCacher.php
line 36
$this->getUrl($request)
in /cms/src/StaticCaching/StaticCacheManager.php
line 49
'base_url' => $this->app['request']->root(),
The request object is not available when running the command from Laravel artisan, and the root url resolved to localhost
and the scheme is set to http
instead of https
.
This caused the $this->getUrl($request)
not able to get the cached version of the url with the actual host.
How to Reproduce
In the .env file, set
CACHE_STRATEGY=full
...
QUEUE_CONNECTION=database
Setup the queue worker to process the queue.
Modify a collection entry and save it.
Inspect the static folder, the cached file still presents, i.e., not removed by invalidator.
Environment
Statamic version: 3.0.39
PHP version: 7.4
FIX:
I managed to make it work by reading the base_url from the .env
file instead of resolving it from the request object.
return array_merge($config, [
'exclude' => $this->app['config']['statamic.static_caching.exclude'] ?? [],
'ignore_query_strings' => $this->app['config']['statamic.static_caching.ignore_query_strings'] ?? false,
'base_url' => env('BASE_URL'), // $this->app['request']->root(),
'locale' => Site::current()->handle(),
]);