cms
cms copied to clipboard
Statically cached pages not removed when moving a page
Bug description
When moving (= changing parent page) or removing a page, its statically cached version remains intact. So after moving or removing a page, one can still visit its frontend URL and view it.
In case of moving a page, when an editor has the frontend of the page open on its old URL, changes suddenly stop appearing in the frontend of the page after moving it. That's rather confusing. I believe it can also cause duplicate content issues.
In case of deleting a page, it's not ideal if the page is still around in the frontend of the site after it's deleted.
I'd expect getting a 404 in both cases. When an entry is moved or deleted, it would be nice if the corresponding static cache file(s) would automatically be deleted 🙂
I'll be out on holiday for the coming week, so it might take me a while to respond if there are any additional questions.
How to reproduce
For moving pages:
- Turn on static caching (in my case, half measure static caching)
- Create a page
- Add some content
- Visit the page URL and keep it open
- Change the page's parent and save the page
- Change the page's content and save again
- Refresh the frontend of the page that was already open. Changes do not come through, nor do you get a 404.
For deleting pages:
- Turn on static caching again
- Create a page
- Visit the page URL, keep it open
- Delete the page
- Refresh the page frontend; it will still show up.
Logs
No response
Environment
Environment
Application Name: {site name}
Laravel Version: 10.26.2
PHP Version: 8.2.15
Composer Version: 2.7.1
Environment: production
Debug Mode: OFF
URL: {site url}
Maintenance Mode: OFF
Cache
Config: CACHED
Events: NOT CACHED
Routes: CACHED
Views: CACHED
Drivers
Broadcasting: log
Cache: statamic
Database: mysql
Logs: stack / single
Mail: postmark
Queue: sync
Session: file
Statamic
Addons: 2
Antlers: runtime
Stache Watcher: Enabled
Static Caching: half
Version: 4.42.1 PRO
Statamic Addons
ddm-studio/cookie-byte: 1.4.3
stoffelio/statamic-turnstile: 1.1.0
Installation
Fresh statamic/statamic site via CLI
Antlers Parser
Runtime (default)
Additional details
No response
Can you please provide config/statamic/sites.php?
@jasonvarga sure:
<?php
return [
/*
|--------------------------------------------------------------------------
| Sites
|--------------------------------------------------------------------------
|
| Each site should have root URL that is either relative or absolute. Sites
| are typically used for localization (eg. English/French) but may also
| be used for related content (eg. different franchise locations).
|
*/
'sites' => [
'default' => [
'name' => config('app.name'),
'locale' => 'nl_NL',
'url' => '/',
],
],
];
Can you try using the app url as the site's URL instead? Like this:
'default' => [
'name' => config('app.name'),
'locale' => 'en_US',
- 'url' => '/',
+ 'url' => config('app.url'),
],
@duncanmcclean sure, I now have the following config:
'default' => [
'name' => config('app.name'),
'locale' => 'nl_NL',
'url' => config('app.url'),
],
However, the problem persists 🙁
Is the APP_URL correct in your .env? Is it https instead of http?
Just checking since ^ fixed some invalidation issues for others recently so want to make sure it's not the same issue here.
Just double-checked it, and yes, it's https, which the site is also on. I also have the issue locally on Laravel Herd. Which is also HTTPS, and properly configured via the .env as well.
In case it helps, my config/statamic/static_caching.php looks like this:
<?php
return [
/*
|--------------------------------------------------------------------------
| Active Static Caching Strategy
|--------------------------------------------------------------------------
|
| To enable Static Caching, you should choose a strategy from the ones
| you have defined below. Leave this null to disable static caching.
|
*/
'strategy' => env('STATAMIC_STATIC_CACHING_STRATEGY', null),
/*
|--------------------------------------------------------------------------
| Caching Strategies
|--------------------------------------------------------------------------
|
| Here you may define all of the static caching strategies for your
| application as well as their drivers.
|
| Supported drivers: "application", "file"
|
*/
'strategies' => [
'half' => [
'driver' => 'application',
'expiry' => null,
],
'full' => [
'driver' => 'file',
'path' => public_path('static'),
'lock_hold_length' => 0,
],
],
/*
|--------------------------------------------------------------------------
| Exclusions
|--------------------------------------------------------------------------
|
| Here you may define a list of URLs to be excluded from static
| caching. You may want to exclude URLs containing dynamic
| elements like contact forms, or shopping carts.
|
*/
'exclude' => [
'class' => null,
'urls' => [
//
],
],
/*
|--------------------------------------------------------------------------
| Invalidation Rules
|--------------------------------------------------------------------------
|
| Here you may define the rules that trigger when and how content would be
| flushed from the static cache. See the documentation for more details.
| If a custom class is not defined, the default invalidator is used.
|
| https://statamic.dev/static-caching
|
*/
'invalidation' => [
'class' => null,
'rules' => [
'collections' => [
'events' => [
'urls' => [
'/agenda',
'/',
]
],
'news' => [
'urls' => [
'/nieuws',
'/',
]
],
'testimonials' => [
'urls' => [
'/ervaringen',
'/'
]
],
'vacancies' => [
'urls' => [
'/vacatures'
]
]
],
'taxonomies' => [
'vacancy_audiences' => [
'urls' => [
'/vacatures',
]
],
'vacancy_branches' => [
'urls' => [
'/vacatures',
]
],
'vacancy_cities' => [
'urls' => [
'/vacatures',
]
],
'vacancy_hours' => [
'urls' => [
'/vacatures',
]
],
'vacancy_industries' => [
'urls' => [
'/vacatures',
]
],
'vacancy_regions' => [
'urls' => [
'/vacatures',
]
],
],
'globals' => [
'newsletter' => [
'urls' => [
'/*'
]
],
'overviews' => [
'urls' => [
'/*'
]
],
'social_media' => [
'urls' => [
'/*'
]
],
],
'navigation' => [
'headermenu' => [
'urls' => [
'/*'
]
],
'footermenu_primary' => [
'urls' => [
'/*'
]
],
'footermenu_secondary' => [
'urls' => [
'/*'
]
],
]
],
],
/*
|--------------------------------------------------------------------------
| Ignoring Query Strings
|--------------------------------------------------------------------------
|
| Statamic will cache pages of the same URL but with different query
| parameters separately. This is useful for pages with pagination.
| If you'd like to ignore the query strings, you may do so.
|
*/
'ignore_query_strings' => false,
/*
|--------------------------------------------------------------------------
| Replacers
|--------------------------------------------------------------------------
|
| Here you may define replacers that dynamically replace content within
| the response. Each replacer must implement the Replacer interface.
|
*/
'replacers' => [
\Statamic\StaticCaching\Replacers\CsrfTokenReplacer::class,
\Statamic\StaticCaching\Replacers\NoCacheReplacer::class,
],
/*
|--------------------------------------------------------------------------
| Warm Queue
|--------------------------------------------------------------------------
|
| Here you may define the name of the queue that requests will be pushed
| onto when warming the static cache using the static:warm command.
|
*/
'warm_queue' => null,
];
To double check this issue, I created a fresh Statamic install. I set the static caching strategy to half, and then followed the steps described above in order to reproduce the problem.
It turns out the problem does not occur when I delete a page. It properly gives a 404 in the frontend after deletion.
However, when I move a page, it's still visible on its old URL. So this narrows the problem down a bit: when moving an entry (= changing its parent entry) the static cache is not properly invalidated.