Skip to content

Commit

Permalink
Merge pull request #254 from moufmouf/cache_improvement
Browse files Browse the repository at this point in the history
Using Native Symfony namespace feature
  • Loading branch information
moufmouf committed Apr 15, 2020
2 parents 208b365 + ee82ed6 commit ebda290
Showing 1 changed file with 15 additions and 13 deletions.
28 changes: 15 additions & 13 deletions src/SchemaFactory.php
Expand Up @@ -104,10 +104,13 @@ class SchemaFactory
private $fieldMiddlewares = [];
/** @var ExpressionLanguage|null */
private $expressionLanguage;
/** @var string */
private $cacheNamespace;

public function __construct(CacheInterface $cache, ContainerInterface $container)
{
$this->cache = new NamespacedCache($cache);
$this->cacheNamespace = substr(md5(Versions::getVersion('thecodingmachine/graphqlite')), 0, 8);
$this->cache = $cache;
$this->container = $container;
}

Expand Down Expand Up @@ -210,8 +213,7 @@ private function getDoctrineAnnotationReader(): Reader

$cache = function_exists('apcu_fetch') ? new ApcuCache() : new PhpFileCache(sys_get_temp_dir() . '/graphqlite.' . crc32(__DIR__));

$namespace = substr(md5(Versions::getVersion('thecodingmachine/graphqlite')), 0, 8);
$cache->setNamespace($namespace);
$cache->setNamespace($this->cacheNamespace);

$doctrineAnnotationReader = new CachedReader($doctrineAnnotationReader, $cache, true);

Expand Down Expand Up @@ -315,18 +317,18 @@ public function createSchema(): Schema
$authenticationService = $this->authenticationService ?: new FailAuthenticationService();
$authorizationService = $this->authorizationService ?: new FailAuthorizationService();
$typeResolver = new TypeResolver();
$cachedDocBlockFactory = new CachedDocBlockFactory($this->cache);
$namespacedCache = new NamespacedCache($this->cache);
$cachedDocBlockFactory = new CachedDocBlockFactory($namespacedCache);
$namingStrategy = $this->namingStrategy ?: new NamingStrategy();
$typeRegistry = new TypeRegistry();
$symfonyCache = new Psr16Adapter($this->cache);
$symfonyCache = new Psr16Adapter($this->cache, $this->cacheNamespace);

$namespaceFactory = new NamespaceFactory($this->cache, $this->classNameMapper, $this->globTTL);
$namespaceFactory = new NamespaceFactory($namespacedCache, $this->classNameMapper, $this->globTTL);
$nsList = array_map(static function (string $namespace) use ($namespaceFactory) {
return $namespaceFactory->createNamespace($namespace);
}, $this->typeNamespaces);

$psr6Cache = new Psr16Adapter($this->cache);
$expressionLanguage = $this->expressionLanguage ?: new ExpressionLanguage($psr6Cache);
$expressionLanguage = $this->expressionLanguage ?: new ExpressionLanguage($symfonyCache);
$expressionLanguage->registerProvider(new SecurityExpressionLanguageProvider());

$fieldMiddlewarePipe = new FieldMiddlewarePipe();
Expand All @@ -338,7 +340,7 @@ public function createSchema(): Schema
$fieldMiddlewarePipe->pipe(new AuthorizationFieldMiddleware($authenticationService, $authorizationService));

$compositeTypeMapper = new CompositeTypeMapper();
$recursiveTypeMapper = new RecursiveTypeMapper($compositeTypeMapper, $namingStrategy, $this->cache, $typeRegistry);
$recursiveTypeMapper = new RecursiveTypeMapper($compositeTypeMapper, $namingStrategy, $namespacedCache, $typeRegistry);

$topRootTypeMapper = new NullableTypeMapperAdapter();

Expand All @@ -354,7 +356,7 @@ public function createSchema(): Schema
$typeRegistry,
$recursiveTypeMapper,
$this->container,
$this->cache,
$namespacedCache,
$this->globTTL
);

Expand Down Expand Up @@ -409,7 +411,7 @@ public function createSchema(): Schema
$annotationReader,
$namingStrategy,
$recursiveTypeMapper,
$this->cache,
$namespacedCache,
$this->globTTL
));
}
Expand All @@ -429,7 +431,7 @@ public function createSchema(): Schema
$inputTypeGenerator,
$recursiveTypeMapper,
$this->container,
$this->cache,
$namespacedCache,
$this->globTTL
);
}
Expand All @@ -447,7 +449,7 @@ public function createSchema(): Schema
$fieldsBuilder,
$this->container,
$annotationReader,
$this->cache,
$namespacedCache,
$this->classNameMapper,
$this->globTTL
);
Expand Down

0 comments on commit ebda290

Please sign in to comment.