Skip to content

Commit

Permalink
Add "Disable fine-grained caching" checker (#282)
Browse files Browse the repository at this point in the history
* Add "Disable fine-grained caching" checker

* Add cache tagging config fallback
  • Loading branch information
M-arcus authored Nov 11, 2024
1 parent 8bb38e9 commit 06ec204
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php

namespace Frosh\Tools\Components\Health\Checker\PerformanceChecker;

use Frosh\Tools\Components\Health\Checker\CheckerInterface;
use Frosh\Tools\Components\Health\HealthCollection;
use Frosh\Tools\Components\Health\SettingsResult;
use Symfony\Component\DependencyInjection\Attribute\Autowire;

class FineGrainedCachingChecker implements PerformanceCheckerInterface, CheckerInterface
{
public const DOCUMENTATION_URL = 'https://developer.shopware.com/docs/guides/hosting/performance/performance-tweaks.html#disable-fine-grained-caching';

public function __construct(
#[Autowire('%kernel.shopware_version%')]
public readonly string $shopwareVersion,
#[Autowire('%shopware.cache.tagging.each_config%')]
public readonly bool $cacheTaggingEachConfig,
#[Autowire('%shopware.cache.tagging.each_snippet%')]
public readonly bool $cacheTaggingEachSnippet,
#[Autowire('%shopware.cache.tagging.each_theme_config%')]
public readonly bool $cacheTaggingEachThemeConfig,
) {}

public function collect(HealthCollection $collection): void
{
if (\version_compare('6.5.4.0', $this->shopwareVersion, '>')) {
return;
}

if ($this->cacheTaggingEachConfig || $this->cacheTaggingEachSnippet || $this->cacheTaggingEachThemeConfig) {
$collection->add(
// only info, because it only affects redis, varnish etc.
SettingsResult::info(
'fine-grained-caching',
'Fine-grained caching on Redis, Varnish etc.',
'enabled',
'disabled',
self::DOCUMENTATION_URL,
),
);
}
}
}
12 changes: 12 additions & 0 deletions src/DependencyInjection/SymfonyConfigCompilerPass.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,17 @@ public function process(ContainerBuilder $container): void
if (!$container->hasParameter('shopware.cart.compression_method')) {
$container->setParameter('shopware.cart.compression_method', false);
}

if (!$container->hasParameter('shopware.cache.tagging.each_config')) {
$container->setParameter('shopware.cache.tagging.each_config', true);
}

if (!$container->hasParameter('shopware.cache.tagging.each_snippet')) {
$container->setParameter('shopware.cache.tagging.each_snippet', true);
}

if (!$container->hasParameter('shopware.cache.tagging.each_theme_config')) {
$container->setParameter('shopware.cache.tagging.each_theme_config', true);
}
}
}

0 comments on commit 06ec204

Please sign in to comment.