Skip to content

Commit 4810d7f

Browse files
committed
Configuring cache for Symfony 5
Symfony 5 does not provide a Simple cache instance by default. This commit adds an already configured cache attached to GraphQLite (APCu with PHPFilesCache fallback)
1 parent 82ead38 commit 4810d7f

File tree

3 files changed

+29
-2
lines changed

3 files changed

+29
-2
lines changed

DependencyInjection/GraphqliteCompilerPass.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,13 @@ public function process(ContainerBuilder $container)
250250
$this->mapAdderToTag('graphql.field_middleware', 'addFieldMiddleware', $container, $schemaFactory);
251251
$this->mapAdderToTag('graphql.type_mapper', 'addTypeMapper', $container, $schemaFactory);
252252
$this->mapAdderToTag('graphql.type_mapper_factory', 'addTypeMapperFactory', $container, $schemaFactory);
253+
254+
// Configure cache
255+
if (ApcuAdapter::isSupported()) {
256+
$container->setAlias('graphqlite.cache', 'graphqlite.apcucache');
257+
} else {
258+
$container->setAlias('graphqlite.cache', 'graphqlite.phpfilescache');
259+
}
253260
}
254261

255262
private function registerController(string $controllerClassName, ContainerBuilder $container): void

Resources/config/container/graphqlite.xml

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313
<defaults autowire="true" autoconfigure="true" public="false" />
1414

1515
<service id="TheCodingMachine\GraphQLite\SchemaFactory">
16-
<argument index="1" type="service" id="service_container" />
16+
<argument type="service" id="graphqlite.psr16cache" />
17+
<argument type="service" id="service_container" />
1718
<call method="setAuthenticationService">
1819
<argument type="service" id="TheCodingMachine\GraphQLite\Security\AuthenticationServiceInterface" />
1920
</call>
@@ -102,5 +103,24 @@
102103
</argument>
103104
<tag name="graphql.type_mapper_factory"/>
104105
</service>
106+
107+
<service id="graphqlite.phpfilescache" class="Symfony\Component\Cache\Adapter\PhpFilesAdapter">
108+
<argument>graphqlite</argument>
109+
</service>
110+
111+
<service id="graphqlite.apcucache" class="Symfony\Component\Cache\Adapter\ApcuAdapter">
112+
<argument>graphqlite</argument>
113+
</service>
114+
115+
<service id="graphqlite.psr16cache" class="Symfony\Component\Cache\Psr16Cache">
116+
<argument type="service" id="graphqlite.cache" />
117+
</service>
118+
119+
<service id="graphqlite.cacheclearer" class="Symfony\Component\HttpKernel\CacheClearer\Psr6CacheClearer">
120+
<argument type="collection">
121+
<argument/>
122+
</argument>
123+
<tag name="kernel.cache_clearer"/>
124+
</service>
105125
</services>
106126
</container>

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
"symfony/security-bundle": "^4.1.9 | ^5",
3535
"symfony/yaml": "^4.1.9 | ^5",
3636
"phpunit/phpunit": "^7.5.1",
37-
"phpstan/phpstan": "^0.10.6",
37+
"phpstan/phpstan-shim": "^0.11.19",
3838
"beberlei/porpaginas": "^1.2",
3939
"php-coveralls/php-coveralls": "^2.1.0"
4040
},

0 commit comments

Comments
 (0)