From 98dffaff2d1b245cad9eeeea28a1f44186b391cc Mon Sep 17 00:00:00 2001 From: Micha Date: Thu, 14 Aug 2025 13:56:37 +0200 Subject: [PATCH 1/4] add/info-and-commands --- guides/hosting/performance/caches.md | 88 ++++++++++++++++++++++++++++ 1 file changed, 88 insertions(+) diff --git a/guides/hosting/performance/caches.md b/guides/hosting/performance/caches.md index a60a309a4..05f383b0f 100644 --- a/guides/hosting/performance/caches.md +++ b/guides/hosting/performance/caches.md @@ -72,3 +72,91 @@ redis://auth@/var/run/redis.sock ``` For more information or other adapters checkout [Symfony FrameworkBundle](https://symfony.com/doc/current/cache.html#configuring-cache-with-frameworkbundle) documentation. + +### Redis Cache Tag Cleanup + +When using Redis as a cache backend with `cache.adapter.redis_tag_aware`, you may encounter an issue where cache tags accumulate over time without proper cleanup. This happens because: + +1. **Cache tags don't have expiry times**: Cache tags themselves don't have TTL (Time To Live) values, even though the actual cache entries do +2. **Namespace accumulation**: Each deployment may create new Redis namespaces, leaving old ones unused +3. **volatile-lru limitation**: The `volatile-lru` eviction policy only removes expired cache entries, not the associated tags + +#### The Problem + +You can verify this issue by checking your Redis instance: + +```bash +# Connect to Redis CLI +redis-cli + +# Check TTL for a cache tag +TTL "ZZiM8ztKU0:\x01tags\x01product-a8682854b7244eaa920513a0a6e84a61" +# Returns: (integer) -1 (meaning no expiry) +``` + +The `-1` response indicates that the tag has no expiry time, which means it will never be automatically removed by Redis. + +#### Why This Happens + +Cache tags are complex to manage because: +- Different cache items can have different expiry times +- Tags need to reference multiple cache entries +- Setting expiry on tags would require calculating the maximum expiry time of all affected caches +- Symfony's default behavior doesn't include automatic tag cleanup + +#### Solutions + +##### 1. Manual Cleanup with FroshTools + +The [FroshTools](https://github.com/FriendsOfShopware/FroshTools) extension provides commands to clean up Redis namespaces and tags: + +```bash +# Clean up old Redis namespaces (run after deployments) +bin/console frosh:redis:namespace:cleanup + +# Clean up orphaned cache tags +bin/console frosh:redis-tag:cleanup + +# Use dry-run option to see what would be cleaned up +bin/console frosh:redis-tag:cleanup --dry-run +``` + +##### 2. Automated Cleanup + +Consider setting up automated cleanup processes: + +```bash +# Add to your deployment script +bin/console frosh:redis:namespace:cleanup +bin/console frosh:redis-tag:cleanup + +# Or set up a cron job +0 2 * * * cd /path/to/shopware && bin/console frosh:redis:namespace:cleanup +0 3 * * * cd /path/to/shopware && bin/console frosh:redis-tag:cleanup +``` + +##### 3. Redis Configuration Optimization + +Ensure your Redis configuration is optimized for cache usage: + +```conf +# redis.conf +maxmemory-policy volatile-lru +maxmemory 2gb +``` + +#### Best Practices + +1. **Run cleanup after deployments**: Always run namespace cleanup after deploying new versions +2. **Monitor tag accumulation**: Regularly check Redis memory usage and tag counts +3. **Use dry-run**: Test cleanup commands with `--dry-run` before executing +4. **Automate the process**: Integrate cleanup into your CI/CD pipeline +5. **Monitor performance**: Watch for any performance impact during cleanup operations + +#### Alternative Approaches + +If tag cleanup becomes a significant issue, consider: + +- Using a different cache backend (e.g., filesystem for smaller installations) +- Implementing custom cache tag management +- Using external reverse proxy caching (Varnish, Fastly) instead of application-level caching From edd3e7f74262189da34e63fc3077f56f4096c320 Mon Sep 17 00:00:00 2001 From: Micha Date: Thu, 14 Aug 2025 13:57:30 +0200 Subject: [PATCH 2/4] remove/unused-info --- guides/hosting/performance/caches.md | 71 +--------------------------- 1 file changed, 2 insertions(+), 69 deletions(-) diff --git a/guides/hosting/performance/caches.md b/guides/hosting/performance/caches.md index 05f383b0f..da08ea421 100644 --- a/guides/hosting/performance/caches.md +++ b/guides/hosting/performance/caches.md @@ -81,82 +81,15 @@ When using Redis as a cache backend with `cache.adapter.redis_tag_aware`, you ma 2. **Namespace accumulation**: Each deployment may create new Redis namespaces, leaving old ones unused 3. **volatile-lru limitation**: The `volatile-lru` eviction policy only removes expired cache entries, not the associated tags -#### The Problem - -You can verify this issue by checking your Redis instance: - -```bash -# Connect to Redis CLI -redis-cli - -# Check TTL for a cache tag -TTL "ZZiM8ztKU0:\x01tags\x01product-a8682854b7244eaa920513a0a6e84a61" -# Returns: (integer) -1 (meaning no expiry) -``` - -The `-1` response indicates that the tag has no expiry time, which means it will never be automatically removed by Redis. - -#### Why This Happens - -Cache tags are complex to manage because: -- Different cache items can have different expiry times -- Tags need to reference multiple cache entries -- Setting expiry on tags would require calculating the maximum expiry time of all affected caches -- Symfony's default behavior doesn't include automatic tag cleanup - -#### Solutions - -##### 1. Manual Cleanup with FroshTools - The [FroshTools](https://github.com/FriendsOfShopware/FroshTools) extension provides commands to clean up Redis namespaces and tags: ```bash # Clean up old Redis namespaces (run after deployments) -bin/console frosh:redis:namespace:cleanup +bin/console frosh:redis-namespace:cleanup # Clean up orphaned cache tags bin/console frosh:redis-tag:cleanup # Use dry-run option to see what would be cleaned up bin/console frosh:redis-tag:cleanup --dry-run -``` - -##### 2. Automated Cleanup - -Consider setting up automated cleanup processes: - -```bash -# Add to your deployment script -bin/console frosh:redis:namespace:cleanup -bin/console frosh:redis-tag:cleanup - -# Or set up a cron job -0 2 * * * cd /path/to/shopware && bin/console frosh:redis:namespace:cleanup -0 3 * * * cd /path/to/shopware && bin/console frosh:redis-tag:cleanup -``` - -##### 3. Redis Configuration Optimization - -Ensure your Redis configuration is optimized for cache usage: - -```conf -# redis.conf -maxmemory-policy volatile-lru -maxmemory 2gb -``` - -#### Best Practices - -1. **Run cleanup after deployments**: Always run namespace cleanup after deploying new versions -2. **Monitor tag accumulation**: Regularly check Redis memory usage and tag counts -3. **Use dry-run**: Test cleanup commands with `--dry-run` before executing -4. **Automate the process**: Integrate cleanup into your CI/CD pipeline -5. **Monitor performance**: Watch for any performance impact during cleanup operations - -#### Alternative Approaches - -If tag cleanup becomes a significant issue, consider: - -- Using a different cache backend (e.g., filesystem for smaller installations) -- Implementing custom cache tag management -- Using external reverse proxy caching (Varnish, Fastly) instead of application-level caching +``` \ No newline at end of file From 7e93d25bb287893297c8ecb8475aae08dd69ac4f Mon Sep 17 00:00:00 2001 From: Micha Date: Thu, 14 Aug 2025 14:02:43 +0200 Subject: [PATCH 3/4] fix: broken-pipelines --- .wordlist.txt | 2 ++ guides/hosting/performance/caches.md | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/.wordlist.txt b/.wordlist.txt index e4c1d6605..6460dc8f8 100644 --- a/.wordlist.txt +++ b/.wordlist.txt @@ -398,6 +398,7 @@ FrameworkBundle FrankenPHP FriendsOfShopware FroshDevelopmentHelper +FroshTools Fullstack GBP GDPR @@ -1475,6 +1476,7 @@ loginViaApi longtext lookups lowerCamelCase +lru lychee macOS mailAware diff --git a/guides/hosting/performance/caches.md b/guides/hosting/performance/caches.md index da08ea421..7fde0bf7f 100644 --- a/guides/hosting/performance/caches.md +++ b/guides/hosting/performance/caches.md @@ -92,4 +92,4 @@ bin/console frosh:redis-tag:cleanup # Use dry-run option to see what would be cleaned up bin/console frosh:redis-tag:cleanup --dry-run -``` \ No newline at end of file +``` From 4522d971dca95c6837d77c7237cde6e375b5edc3 Mon Sep 17 00:00:00 2001 From: Micha Date: Thu, 14 Aug 2025 14:06:11 +0200 Subject: [PATCH 4/4] add: experimental-info --- guides/hosting/performance/caches.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/guides/hosting/performance/caches.md b/guides/hosting/performance/caches.md index 7fde0bf7f..da2d667d0 100644 --- a/guides/hosting/performance/caches.md +++ b/guides/hosting/performance/caches.md @@ -81,7 +81,7 @@ When using Redis as a cache backend with `cache.adapter.redis_tag_aware`, you ma 2. **Namespace accumulation**: Each deployment may create new Redis namespaces, leaving old ones unused 3. **volatile-lru limitation**: The `volatile-lru` eviction policy only removes expired cache entries, not the associated tags -The [FroshTools](https://github.com/FriendsOfShopware/FroshTools) extension provides commands to clean up Redis namespaces and tags: +The [FroshTools](https://github.com/FriendsOfShopware/FroshTools) extension provides **experimental** commands to clean up Redis namespaces and tags: ```bash # Clean up old Redis namespaces (run after deployments)