Skip to content

Commit de04aba

Browse files
authored
Merge pull request #310 from MattBred/patch-1
Update SchemaFactory to allow the annotation cache dir to be configurable
2 parents e613729 + a88a534 commit de04aba

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

src/SchemaFactory.php

+15-1
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,8 @@ class SchemaFactory
8787
private $parameterMiddlewares = [];
8888
/** @var Reader */
8989
private $doctrineAnnotationReader;
90+
/** @var string */
91+
private $annotationCacheDir;
9092
/** @var AuthenticationServiceInterface|null */
9193
private $authenticationService;
9294
/** @var AuthorizationServiceInterface|null */
@@ -204,6 +206,13 @@ public function setDoctrineAnnotationReader(Reader $annotationReader): self
204206
return $this;
205207
}
206208

209+
public function setAnnotationCacheDir(string $cacheDir): self
210+
{
211+
$this->annotationCacheDir = $cacheDir;
212+
213+
return $this;
214+
}
215+
207216
/**
208217
* Returns a cached Doctrine annotation reader.
209218
* Note: we cannot get the annotation reader service in the container as we are in a compiler pass.
@@ -214,7 +223,12 @@ private function getDoctrineAnnotationReader(): Reader
214223
AnnotationRegistry::registerLoader('class_exists');
215224
$doctrineAnnotationReader = new DoctrineAnnotationReader();
216225

217-
$cache = function_exists('apcu_fetch') ? new ApcuCache() : new PhpFileCache(sys_get_temp_dir() . '/graphqlite.' . crc32(__DIR__));
226+
if (function_exists('apcu_enabled') && apcu_enabled()) {
227+
$cache = new ApcuCache();
228+
} else {
229+
$cacheDir = $this->annotationCacheDir ?? sys_get_temp_dir();
230+
$cache = new PhpFileCache($cacheDir . '/graphqlite.' . crc32(__DIR__));
231+
}
218232

219233
$cache->setNamespace($this->cacheNamespace);
220234

0 commit comments

Comments
 (0)