Skip to content

Commit

Permalink
Merge pull request #5 from mothership-gmbh/dev
Browse files Browse the repository at this point in the history
Shopware 6.5 compatibility
  • Loading branch information
niklaswolf authored Nov 15, 2023
2 parents f2a955b + f2847c9 commit 6bec8cb
Show file tree
Hide file tree
Showing 12 changed files with 65 additions and 126 deletions.
90 changes: 0 additions & 90 deletions Adapter/Cache/CacheItemPool.php

This file was deleted.

4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# 2.0.0
- Shopware 6.5 compatibility
- removed custom cache pool and override of `CacheClearer` in favour of a new cache clearer using the tag `kernel.
cache_clearer`. This is no change in functionality, just refactoring.
3 changes: 3 additions & 0 deletions Cache/GatewayInterface.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
<?php

declare(strict_types=1);

namespace Mothership\HeadlessShopwareVarnishCacheBundle\Cache;

interface GatewayInterface {
Expand Down
17 changes: 17 additions & 0 deletions Cache/VarnishCacheClearer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php declare(strict_types=1);

namespace Mothership\HeadlessShopwareVarnishCacheBundle\Cache;

use Symfony\Component\HttpKernel\CacheClearer\CacheClearerInterface;

class VarnishCacheClearer implements CacheClearerInterface
{
public function __construct(protected readonly GatewayInterface $gateway)
{
}

public function clear(string $cacheDir): void
{
$this->gateway->invalidate(['all']);
}
}
5 changes: 2 additions & 3 deletions Cache/VarnishGateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,8 @@ public function flushCollected(): void
{
$requests = [];
/**
* Wenn Properties via API aktualisiert werden, werden alle Produkte gepurged. Um nicht mehrere
* tausend Purge Requests zu schicken, schicken wir einen Purge-All-Tag, wenn ein Limit erreicht ist.
*
* When properties are updated via API, all products are purged. To avoid sending several thousand purge
* requests, we send a purge all tag when a limit is reached.
* @see \Shopware\Core\Framework\Adapter\Cache\CacheInvalidationSubscriber::getChangedPropertyFilterTags
*/
if (count($this->invalidateTags) > $this->tagFlushThreshold) {
Expand Down
16 changes: 9 additions & 7 deletions DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace Mothership\HeadlessShopwareVarnishCacheBundle\DependencyInjection;

use Symfony\Component\Config\Definition\Builder\TreeBuilder;
Expand All @@ -11,20 +13,20 @@ class Configuration implements ConfigurationInterface
/**
* @inheritDoc
*/
public function getConfigTreeBuilder()
public function getConfigTreeBuilder(): TreeBuilder
{
$treeBuilder = new TreeBuilder('headless_shopware_varnish_cache');
$treeBuilder->getRootNode()
->children()
->booleanNode('enabled')->defaultFalse()->end()
->arrayNode('reverse_proxy')
?->arrayNode('reverse_proxy')
->children()
->variableNode('hosts')->defaultNull()->end()
->scalarNode('max_parallel_invalidations')->end()
->scalarNode('ban_method')->end()
->scalarNode('tag_flush_threshold')->end()
->booleanNode('use_xkey')->defaultFalse()->end()
->scalarNode('xkey_chunksize')->defaultValue(50)->end();
?->scalarNode('max_parallel_invalidations')->end()
?->scalarNode('ban_method')->end()
?->scalarNode('tag_flush_threshold')->end()
?->booleanNode('use_xkey')->defaultFalse()->end()
?->scalarNode('xkey_chunksize')->defaultValue(50)->end();
return $treeBuilder;
}
}
10 changes: 6 additions & 4 deletions DependencyInjection/HeadlessShopwareVarnishCacheExtension.php
Original file line number Diff line number Diff line change
@@ -1,22 +1,24 @@
<?php

declare(strict_types=1);

namespace Mothership\HeadlessShopwareVarnishCacheBundle\DependencyInjection;

use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Extension\Extension;
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
use function is_array;

class HeadlessShopwareVarnishCacheExtension extends Extension
{

/**
* @inheritDoc
*/
public function load(array $configs, ContainerBuilder $container)
public function load(array $configs, ContainerBuilder $container): void
{
$configuration = new Configuration();
$config = $this->processConfiguration($configuration, $configs);
$this->addConfig($container, "headless_shopware_varnish_cache", $config);
$this->addConfig($container, 'headless_shopware_varnish_cache', $config);
}

/**
Expand All @@ -30,7 +32,7 @@ private function addConfig(ContainerBuilder $container, string $alias, array $op
foreach ($options as $key => $option) {
$container->setParameter($alias . '.' . $key, $option);

if (\is_array($option)) {
if (is_array($option)) {
$this->addConfig($container, $alias . '.' . $key, $option);
}
}
Expand Down
11 changes: 10 additions & 1 deletion Event/RequestSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ public static function getSubscribedEvents(): array
}

/**
* Der Worker beendet sich nach 60 sekunden. Siehe supervisor configuration.
* Worker stops after 60s. See worker/supervisor configuration
* Flush all collected tags in this case.
*
* @return void
*/
Expand All @@ -42,11 +43,19 @@ public function onWorkerStopped(): void
$this->varnishGateway->flushCollected();
}

/**
* When a request is finished, flush all collected invalidation tags, instead of flushing every tag on its own
* @return void
*/
public function onKernelFinish(): void
{
$this->varnishGateway->flushCollected();
}

/**
* Same as for request finish, just for CLI commands.
* @return void
*/
public function onConsoleTerminate(): void
{
$this->varnishGateway->flushCollected();
Expand Down
5 changes: 3 additions & 2 deletions Event/ReverseProxyCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,10 @@ public function __invoke(InvalidateCacheEvent $event): void
}

/**
* @param Request $request
* @return Response|null
*/
public function lookup(Request $request)
public function lookup(Request $request): ?Response
{
return null;
}
Expand Down Expand Up @@ -86,7 +87,7 @@ public function purge(string $url): bool
}

/**
* We don't need an cleanup
* We don't need cleanup
*/
public function cleanup(): void
{
Expand Down
6 changes: 5 additions & 1 deletion HeadlessShopwareVarnishCacheBundle.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,14 @@

use Mothership\HeadlessShopwareVarnishCacheBundle\DependencyInjection\HeadlessShopwareVarnishCacheExtension;
use Shopware\Core\Framework\Bundle;
use Symfony\Component\DependencyInjection\Extension\ExtensionInterface;

class HeadlessShopwareVarnishCacheBundle extends Bundle
{
public function getContainerExtension()
/**
* @return ExtensionInterface|null
*/
public function getContainerExtension(): ?ExtensionInterface
{
return new HeadlessShopwareVarnishCacheExtension();
}
Expand Down
16 changes: 2 additions & 14 deletions Resources/config/services.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,21 +34,9 @@
<argument type="service" id="Mothership\HeadlessShopwareVarnishCacheBundle\Cache\VarnishGateway"/>
</service>

<service id="Mothership\HeadlessShopwareVarnishCacheBundle\Adapter\Cache\CacheItemPool">
<service id="Mothership\HeadlessShopwareVarnishCacheBundle\Cache\VarnishCacheClearer">
<argument type="service" id="Mothership\HeadlessShopwareVarnishCacheBundle\Cache\VarnishGateway" />
</service>

<service id="Shopware\Core\Framework\Adapter\Cache\CacheClearer">
<argument type="collection">
<argument type="service" id="cache.object"/>
<argument type="service" id="cache.http"/>
<argument type="service" id="Mothership\HeadlessShopwareVarnishCacheBundle\Adapter\Cache\CacheItemPool"/>
</argument>
<argument type="service" id="cache_clearer"/>
<argument type="service" id="filesystem"/>
<argument>%kernel.cache_dir%</argument>
<argument>%kernel.environment%</argument>
<argument type="service" id="messenger.bus.shopware"/>
<tag name="kernel.cache_clearer"/>
</service>
</services>
</container>
8 changes: 4 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@
}
],
"require": {
"php": ">=7.4",
"shopware/core": "^v6.4.18",
"shopware/storefront": "^v6.4.18"
"php": ">=8.1",
"shopware/core": "^v6.5",
"shopware/storefront": "^v6.5"
},
"require-dev": {
"symfony/dependency-injection": "^5 | ^6"
"symfony/dependency-injection": "^6"
},
"autoload": {
"psr-4": {
Expand Down

0 comments on commit 6bec8cb

Please sign in to comment.