Skip to content

Commit 3b5e632

Browse files
SpiGAndromedaIsengo1989Copilot
authored
docs: document cache:clear:all and cache hash behavior (#2088)
* docs: document cache:clear:all confirmation behavior * docs: document cache:clear:all confirmation and hash implications * chore: add CacheClearCommand and NFS to spellcheck wordlist * docs(cache): remove cache:clear:all confirmation prompt references Removes documentation about the interactive confirmation prompt and --force flag for the cache:clear:all command across all guide pages. * Update resources/references/core-reference/commands-reference.md Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update guides/plugins/plugins/framework/caching/index.md Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * chore/grammar * chore/grammar * chore/streamline-command-descriptions * fix/other-prs-spellcheck * fix/other-usage --------- Co-authored-by: Micha Hobert <m.hobert@shopware.com> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent 9ee765f commit 3b5e632

6 files changed

Lines changed: 102 additions & 74 deletions

File tree

.wordlist.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ CSP
129129
CSPs
130130
CSRF
131131
CSV
132+
CacheClearCommand
132133
CacheInvalidator
133134
CacheInvalidatorS
134135
CachedProductListingRouteTest
@@ -586,6 +587,7 @@ MyPlugin
586587
MyTestClass
587588
MyTestInterface
588589
NATS
590+
NFS
589591
NPM
590592
NUR
591593
NVDA

guides/hosting/infrastructure/reverse-http-cache.md

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ It contains the Shopware default VCL (Varnish Configuration Language). The conta
3737

3838
:::warning
3939
From version v6.6.x onwards, this method is deprecated and will be removed in v6.7.0.
40-
Utilising Varnish with Redis involves LUA scripts to determine URLs for the BAN request.
40+
Using Varnish with Redis involves LUA scripts to determine URLs for the BAN request.
4141
This can cause problems depending on the setup or network.
4242
Furthermore, Redis clusters are not supported.
4343
Therefore, it is advisable to opt for the [Varnish with `XKey`](#configure-varnish) integration instead.
@@ -76,17 +76,17 @@ Make sure to create a Symfony configuration to make it configurable again, as sh
7676
:::
7777

7878
For the most part, using Symfony and Varnish doesn't cause any problem.
79-
But, when a request passes through a proxy, certain request information is sent using either the *standard Forwarded* header or *X-Forwarded* headers.
79+
But when a request passes through a proxy, certain request information is sent using either the *standard Forwarded* header or *X-Forwarded* headers.
8080
For example, instead of reading the `REMOTE_ADDR` header (which will now be the IP address of your reverse proxy), the user's true IP will be stored in a standard Forwarded: for="..." header or an *X-Forwarded-For* header.
8181

8282
If you don't configure Symfony to look for these headers, you will get incorrect information about the client's IP address.
8383
Whether or not the client connects via HTTPS, the client's port and the hostname are requested.
8484

85-
Go through [Proxies](https://symfony.com/doc/current/deployment/proxies.html) section for more information.
85+
Go through [the Proxies](https://symfony.com/doc/current/deployment/proxies.html) section for more information.
8686

8787
### Varnish Docker Image
8888

89-
Shopware offers a Varnish Docker image that is pre-configured to work with Shopware.
89+
Shopware offers a Varnish Docker image pre-configured to work with Shopware.
9090
Find the [image](https://github.com/shopware/varnish-shopware) here.
9191
The image is based on the official Varnish image and contains the Shopware default VCL with few configurations as environment variables.
9292

@@ -96,7 +96,7 @@ Varnish `XKey` is a cache key module that allows you to use Varnish with surroga
9696
It is a module not included in the default Varnish installation.
9797
It is available for Varnish 6.0 or higher.
9898

99-
Checkout the official Varnish installation guide [here](https://github.com/varnish/varnish-modules#installation).
99+
Check out the official Varnish installation guide [here](https://github.com/varnish/varnish-modules#installation).
100100

101101
And also needs to be enabled in the `config/packages/shopware.yml` file:
102102

@@ -120,7 +120,7 @@ Make sure to replace the `__XXX__` placeholders with your actual values.
120120
The default configuration Varnish uses hard purges, so when you update a product, the page will be removed from the cache and the next request takes longer because the cache is empty.
121121
To avoid this, you can use soft purges.
122122
Soft purge keeps the old page in case and serves it still to the clients and refreshes the cache in the background.
123-
This way the client gets **always** a cached page and the cache is updated in the background.
123+
This way the client gets **always** a cached page, and the cache is updated in the background.
124124

125125
To enable soft purge, you need to change the varnish configuration.
126126

@@ -177,17 +177,17 @@ shopware:
177177
This feature has been introduced with Shopware version 6.4.15.0
178178
:::
179179
180-
By default, the cache will be immediately purged and the next requesting user will get a slow response as the cache has been deleted.
180+
By default, the cache will be immediately purged, and the next requesting user will get a slow response as the cache has been deleted.
181181
On soft purge, the user still gets the cached response after the purge, but in the configured time interval, the cache will be refreshed.
182182
This makes sure that the client gets the fastest response possible.
183183
184184
```yaml
185185
# Be aware that the configuration key changed from `storefront.reverse_proxy` to `shopware.http_cache.reverse_proxy` starting with Shopware 6.6
186186
shopware:
187187
http_cache:
188-
# Allow to serve the out-dated cache for 300 seconds
188+
# Allow to serve the outdated cache for 300 seconds
189189
stale_while_revalidate: 300
190-
# Allow to serve the out-dated cache for an hour if the origin server is offline
190+
# Allow to serve the outdated cache for an hour if the origin server is offline
191191
stale_if_error: 3600
192192
reverse_proxy:
193193
enabled: true
@@ -214,9 +214,9 @@ So, when a product is invalidated, the object cache and the HTTP cache will also
214214
There are a few different cache clearing commands:
215215
216216
1. `bin/console cache:clear` - Clears and warms up the application cache (In versions before 6.7 this command also cleared the HTTP cache)
217-
2. `bin/console cache:clear:all` - Clears everything, including application cache, cache pools and the HTTP cache (Since version 6.6.8)
217+
2. `bin/console cache:clear:all` - Clears everything, including application cache, cache pools, HTTP cache, and other kernel cache directories (Since version 6.6.8)
218218
3. `bin/console cache:clear:http` - Clears the reverse proxy cache if enabled, if not it clears the `http` cache pool (Since version 6.6.10)
219-
4. `bin/console cache:pool:clear --all` - Clears only the object cache (Useful for when you don't want to clear the http cache, pre version 6.6.10)
219+
4. `bin/console cache:pool:clear --all` - Clears only the object cache (Useful for when you don't want to clear the http cache, pre-version 6.6.10)
220220

221221
If you only want to clear the http cache, use `bin/console cache:clear:http`
222222

guides/hosting/installation-updates/deployments/build-w-o-db.md

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1375,4 +1375,16 @@ index.json
13751375

13761376
### Partially compiling the Storefront
13771377

1378-
You can also build just the Javascript bundle using `CI=1 SHOPWARE_SKIP_THEME_COMPILE=true PUPPETEER_SKIP_CHROMIUM_DOWNLOAD=true bin/build-storefront.sh` (without the need for the above loader) in your CI. After that, run `bin/console theme:dump` on your production system when the database is available. This will happen automatically if theme variables are changed via the admin panel.
1378+
You can also build just the JavaScript bundle using `CI=1 SHOPWARE_SKIP_THEME_COMPILE=true PUPPETEER_SKIP_CHROMIUM_DOWNLOAD=true bin/build-storefront.sh` (without the need for the above loader) in your CI. After that, run `bin/console theme:dump` on your production system when the database is available. This will happen automatically if theme variables are changed via the admin panel.
1379+
1380+
## Cache directory and hash implications
1381+
1382+
When using `bin/ci` or `ComposerPluginLoader`, the cache directory name includes a hash computed from active plugins. Since `ComposerPluginLoader` marks all Composer-installed plugins as active, while `DbalKernelPluginLoader` (used by web requests) respects the database `active` column, the cache hashes can differ.
1383+
1384+
This means:
1385+
1386+
- Cache warmed with `bin/ci` uses a hash based on all Composer-installed plugins being active
1387+
- Production web requests use a hash based on the actual database plugin state
1388+
- If any plugin is deactivated in the database, web requests create a new cache directory
1389+
1390+
To ensure cache is properly cleared across all configurations, use `cache:clear:all` instead of `cache:clear` in deployment scripts.

guides/plugins/apps/app-base-guide.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ If the changes are still not visible, try:
8585
bin/console cache:clear:http
8686
```
8787

88-
or
88+
or for a complete cache reset:
8989

9090
```bash
9191
bin/console cache:clear:all
@@ -109,8 +109,8 @@ This process is called setup.
109109
:::
110110

111111
::: warning
112-
Suppose your app makes use of the Admin Module, Payment Method, Tax providers or Webhook app system features.
113-
In that case, you need to implement the registration, to exchange a secret key; that is later used to authenticate the shops.
112+
Suppose your app makes use of the Admin Module, Payment Method, Tax providers, or Webhook app system features.
113+
In that case, you need to implement the registration to exchange a secret key; that is later used to authenticate the shops.
114114
:::
115115

116116
During the setup, it is verified that Shopware connects to the right backend server and keys are exchanged to secure all further communications.
@@ -161,7 +161,7 @@ shopware-app-signature: a8830aface4ac4a21be94844426e62c77078ca9a10f694737b75ca15
161161
sw-version: 6.4.5.0
162162
```
163163

164-
Additionally, the `shopware-app-signature` header will be provided, which contains a cryptographic signature of the query string.
164+
Additionally, the `shopware-app-signature` header will be provided, which contains a cryptographic signature of the query string.
165165
The secret used to generate this signature is the `app secret`, which is unique per app and will be provided by the Shopware Account if you upload your app to the store.
166166
This secret won't leave the Shopware Account, so it won't even be leaked to the shops installing your app.
167167

@@ -317,7 +317,7 @@ Starting from Shopware version 6.4.1.0, the current Shopware version will be sen
317317
Starting from Shopware version 6.4.5.0, the current language id of the Shopware context will be sent as a `sw-context-language` header, and the locale of the user or locale of the context language is available under the `sw-user-language` header.
318318
:::
319319

320-
The request is signed with the `shop-secret` that your app provided in the [registration response](app-base-guide#registration-response) and the signature can be found in the `shopware-shop-signature` header.
320+
The request is signed with the `shop-secret` that your app provided in the [registration response](app-base-guide#registration-response) and the signature can be found in the `shopware-shop-signature` header.
321321
You need to recalculate that signature and check that it matches the provided one to make sure that the request is really sent from the shop with that shopId.
322322

323323
You can use the following code snippet to generate the signature:

guides/plugins/plugins/framework/caching/index.md

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -409,6 +409,20 @@ sw-force-cache-invalidate: 1
409409
## Manual cache clear
410410

411411
You can also manually clear the caches when you performed some actions that made a cache invalidation necessary, but where it was not triggered automatically.
412-
To clear all caches, you can execute the `cache:clear:all` command, which clears the HTTP-Cache, the object caches as well as any other caches that are registered in the system.
412+
413+
To clear all caches, you can execute the `cache:clear:all` command, which clears the HTTP-Cache and the object caches, and removes other kernel cache directories.
414+
413415
The `cache:clear` command on the other hand will only clear the object caches, but won't invalidate the HTTP-Cache.
414416
On the other hand, the `cache:clear:http` command will clear the complete HTTP-Cache, but won't invalidate the object caches.
417+
418+
::: warning
419+
`cache:clear` only clears the cache directory matching the current kernel's configuration. If you run `bin/console cache:clear` but web requests still use stale cache, the CLI and web server may be using different cache directories. This can happen when plugins are in different states (e.g., installed via Composer but not yet activated in the database). Use `cache:clear:all` to clear all cache variants.
420+
:::
421+
422+
::: details How cache:clear works internally
423+
The Symfony `cache:clear` command uses an atomic directory swap to ensure the application always has a valid cache. It first removes any leftover temporary directories, then creates and warms up the new cache in `var/cache/{env}_new/`. Once ready, it renames the current cache directory to a backup and moves the new one into place. Finally, it removes the backup.
424+
425+
This approach ensures zero downtime because the application always has a working cache directory. The swap uses filesystem rename operations which are atomic on most systems. On NFS filesystems, directories are deleted instead of renamed due to limitations with atomic operations.
426+
427+
For more details, see the [Symfony CacheClearCommand source](https://github.com/symfony/symfony/blob/7.4/src/Symfony/Bundle/FrameworkBundle/Command/CacheClearCommand.php).
428+
:::

0 commit comments

Comments
 (0)