Skip to content

Commit

Permalink
NEXT-39316 - MySQL cache invalidator adapter (#1628)
Browse files Browse the repository at this point in the history
* NEXT-39316 - MySQL cache invalidator adapter

* Update guides/hosting/performance/performance-tweaks.md

---------

Co-authored-by: Micha Hobert <[email protected]>
  • Loading branch information
AydinHassan and Isengo1989 authored Jan 7, 2025
1 parent adcd61c commit b7c495b
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion guides/hosting/performance/performance-tweaks.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,17 @@ shopware:
### Delayed invalidation
A delay for cache invalidation can be activated for systems with a high update frequency for the inventory (products, categories). Once the instruction to delete the cache entries for a specific product or category occurs, they are not deleted instantly but processed by a background task later. Thus, if two processes invalidate the cache in quick succession, the timer for the invalidation of this cache entry will only reset.
A delay for cache invalidation can be activated for systems with a high update frequency for the inventory (products, categories). Once the instruction to delete the cache entries for a specific product or category occurs, they are not deleted instantly but processed later by a background task. Thus, if two processes invalidate the cache in quick succession, the timer for the invalidation of this cache entry will only reset.
By default, the scheduled task will run every 20 seconds, but the interval can be adjusted over the `scheduled_taks` DB table, by setting the `run_interval` to the desired value (it is configured in seconds) for the entry with the name `shopware.invalidate_cache`.

::: warning
If you enable delayed cache invalidation, you must set up a worker to run [Scheduled Tasks](../infrastructure/scheduled-task), e.g., using the [Message Queue](../infrastructure/message-queue).
:::

There are two possible storages/adapters for delayed cache invalidation: Redis and MySQL. Redis is preferred since it handles retrieving and deleting keys in an atomic manner. MySQL also supports it, but it's more complicated, and at a certain load, deadlocks are inevitable. If you already use Redis, use it also for the delayed cached. The MySQL adapter should only be used when you cannot use Redis.

Redis:

```yaml
# config/packages/prod/shopware.yaml
shopware:
Expand All @@ -53,6 +57,18 @@ shopware:
connection: 'ephemeral' # connection name from redis configuration
```

MySQL:

```yaml
# config/packages/prod/shopware.yaml
shopware:
cache:
invalidation:
delay: 1 # 0 = disabled, 1 = enabled
delay_options:
storage: mysql
```

## MySQL configuration

Shopware sets some MySQL configuration variables on each request to ensure it works in any environment. You can disable this behavior if you have correctly configured your MySQL server.
Expand Down

0 comments on commit b7c495b

Please sign in to comment.