diff --git a/src/SchemaFactory.php b/src/SchemaFactory.php index a697fe9fd7..3b984bbaed 100644 --- a/src/SchemaFactory.php +++ b/src/SchemaFactory.php @@ -86,6 +86,8 @@ class SchemaFactory private $parameterMiddlewares = []; /** @var Reader */ private $doctrineAnnotationReader; + /** @var string */ + private $annotationCacheDir; /** @var AuthenticationServiceInterface|null */ private $authenticationService; /** @var AuthorizationServiceInterface|null */ @@ -203,6 +205,13 @@ public function setDoctrineAnnotationReader(Reader $annotationReader): self return $this; } + public function setAnnotationCacheDir(string $cacheDir): self + { + $this->annotationCacheDir = $cacheDir; + + return $this; + } + /** * Returns a cached Doctrine annotation reader. * Note: we cannot get the annotation reader service in the container as we are in a compiler pass. @@ -213,7 +222,12 @@ private function getDoctrineAnnotationReader(): Reader AnnotationRegistry::registerLoader('class_exists'); $doctrineAnnotationReader = new DoctrineAnnotationReader(); - $cache = function_exists('apcu_fetch') ? new ApcuCache() : new PhpFileCache(sys_get_temp_dir() . '/graphqlite.' . crc32(__DIR__)); + if (function_exists('apcu_enabled') && apcu_enabled()) { + $cache = new ApcuCache(); + } else { + $cacheDir = $this->annotationCacheDir ?? sys_get_temp_dir(); + $cache = new PhpFileCache($cacheDir . '/graphqlite.' . crc32(__DIR__)); + } $cache->setNamespace($this->cacheNamespace);