Skip to content

Commit 43d4963

Browse files
committed
OXDEV-8670 Use FileSystem adapter for cache
1 parent 80ad5ad commit 43d4963

7 files changed

Lines changed: 102 additions & 12 deletions

File tree

CHANGELOG-v11.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
66

77
## [11.0.0] - unreleased
88

9+
### Added
10+
- FilesystemAdapter as schema caching solution
11+
- CacheClearCommand allowing to manually clear schema cache
12+
913
### Changed
1014
- Update module to work with OXID eShop 7.3
1115
- Replaced `TokenFilterList::fromUserInput` and `TokenSorting::fromUserInput` with direct object instantiation

services.yaml

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,10 @@ services:
118118
tags: [ 'kernel.event_subscriber' ]
119119

120120
oxidesales.graphqlbase.cacheadapter:
121-
class: Symfony\Component\Cache\Adapter\NullAdapter
121+
class: Symfony\Component\Cache\Adapter\FilesystemAdapter
122+
arguments:
123+
$namespace: 'oe_graphql_base-schema'
124+
$directory: '@=service("OxidEsales\\EshopCommunity\\Internal\\Transition\\Utility\\ContextInterface").getCacheDirectory()'
122125

123126
oxidesales.graphqlbase.cache:
124127
class: Symfony\Component\Cache\Psr16Cache
@@ -128,3 +131,10 @@ services:
128131
OxidEsales\GraphQL\Base\Service\PermissionProvider:
129132
class: OxidEsales\GraphQL\Base\Service\PermissionProvider
130133
tags: [ 'graphql_permission_provider' ]
134+
135+
OxidEsales\GraphQL\Base\Command\CacheClearCommand:
136+
class: OxidEsales\GraphQL\Base\Command\CacheClearCommand
137+
arguments:
138+
$cache: '@oxidesales.graphqlbase.cache'
139+
tags:
140+
- { name: 'console.command', command: 'oe:graphql:cache-clear' }

src/Command/CacheClearCommand.php

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<?php
2+
3+
/**
4+
* Copyright © OXID eSales AG. All rights reserved.
5+
* See LICENSE file for license details.
6+
*/
7+
8+
declare(strict_types=1);
9+
10+
namespace OxidEsales\GraphQL\Base\Command;
11+
12+
use Psr\SimpleCache\CacheInterface;
13+
use Symfony\Component\Console\Command\Command;
14+
use Symfony\Component\Console\Input\InputInterface;
15+
use Symfony\Component\Console\Output\OutputInterface;
16+
17+
class CacheClearCommand extends Command
18+
{
19+
public function __construct(private readonly CacheInterface $cache)
20+
{
21+
parent::__construct();
22+
}
23+
24+
protected function configure()
25+
{
26+
$this
27+
->setName('oe:graphql:cache-clear')
28+
->setDescription('Clear schema cache');
29+
}
30+
31+
/**
32+
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
33+
*/
34+
protected function execute(InputInterface $input, OutputInterface $output)
35+
{
36+
$output->writeln('<info>Clearing schema cache...</info>');
37+
$this->cache->clear();
38+
$output->writeln('<info>Schema cache cleared.</info>');
39+
40+
return Command::SUCCESS;
41+
}
42+
}

src/Event/Subscriber/ModuleChangeSubscriber.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
class ModuleChangeSubscriber implements EventSubscriberInterface
2020
{
21+
/** @phpstan-ignore property.onlyWritten */
2122
public function __construct(private readonly CacheInterface $cache)
2223
{
2324
}
@@ -29,9 +30,6 @@ public function __construct(private readonly CacheInterface $cache)
2930
*/
3031
public function handle(Event $event): Event
3132
{
32-
//clear entire cache
33-
$this->cache->clear();
34-
3533
return $event;
3634
}
3735

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,12 @@
1010
namespace OxidEsales\GraphQL\Base\Framework;
1111

1212
use AppendIterator;
13+
use IteratorIterator;
1314
use Kcs\ClassFinder\Finder\FinderInterface;
14-
use Kcs\ClassFinder\Finder\Psr4Finder;
1515
use Kcs\ClassFinder\Finder\ReflectionFilterTrait;
1616
use Traversable;
1717

18-
/**
19-
* @internal This class is not covered by the backward compatibility promise
20-
*/
21-
class Psr4AggregatedFinder implements FinderInterface
18+
class AggregatedFinder implements FinderInterface
2219
{
2320
use ReflectionFilterTrait;
2421

@@ -29,9 +26,9 @@ public function __construct()
2926
$this->iterator = new AppendIterator();
3027
}
3128

32-
public function addFinder(Psr4Finder $finder): void
29+
public function addFinder(FinderInterface $finder): void
3330
{
34-
$this->iterator->append($finder->getIterator());
31+
$this->iterator->append(new IteratorIterator($finder->getIterator()));
3532
}
3633

3734
public function getIterator(): Traversable

src/Framework/SchemaFactory.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public function getSchema(): Schema
6060
$this->container
6161
);
6262

63-
$finder = new Psr4AggregatedFinder();
63+
$finder = new AggregatedFinder();
6464

6565
foreach ($this->namespaceMappers as $namespaceMapper) {
6666
foreach ($namespaceMapper->getControllerNamespaceMapping() as $namespace => $path) {
@@ -81,6 +81,8 @@ public function getSchema(): Schema
8181
$factory->setAuthenticationService($this->authentication)
8282
->setAuthorizationService($this->authorization);
8383

84+
$factory->prodMode();
85+
8486
$this->schema = $factory->createSchema();
8587
$queryTimer->stop();
8688

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?php
2+
3+
/**
4+
* Copyright © OXID eSales AG. All rights reserved.
5+
* See LICENSE file for license details.
6+
*/
7+
8+
declare(strict_types=1);
9+
10+
namespace OxidEsales\GraphQL\Base\Tests\Unit\Framework;
11+
12+
use ArrayIterator;
13+
use Kcs\ClassFinder\Finder\FinderInterface;
14+
use OxidEsales\GraphQL\Base\Framework\AggregatedFinder;
15+
use OxidEsales\GraphQL\Base\Tests\Unit\BaseTestCase;
16+
17+
class AggregatedFinderTest extends BaseTestCase
18+
{
19+
public function testGetIterator(): void
20+
{
21+
$elements = [
22+
[uniqid() => uniqid(), uniqid() => uniqid()],
23+
[uniqid() => uniqid(), uniqid() => uniqid()],
24+
];
25+
26+
$finder = new AggregatedFinder();
27+
$finder->addFinder($this->createConfiguredMock(FinderInterface::class, [
28+
'getIterator' => new ArrayIterator($elements[0]),
29+
]));
30+
$finder->addFinder($this->createConfiguredMock(FinderInterface::class, [
31+
'getIterator' => new ArrayIterator($elements[1]),
32+
]));
33+
34+
$array = iterator_to_array($finder->getIterator());
35+
$this->assertEquals($elements[0] + $elements[1], $array);
36+
}
37+
}

0 commit comments

Comments
 (0)