-
Notifications
You must be signed in to change notification settings - Fork 104
Update SchemaFactory to allow the annotation cache dir to be configurable #310
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Hey @MattBred , Thanks a lot for this PR. If you don't mind, I'll keep it open for now. Not sure yet, but until I make my mind, I would like to avoid adding an additional parameter to the SchemaFactory constructor (since that parameter might disappear soon!) |
Sounds good @moufmouf . I've found a few places in graphqlite + the symfony bundle that use the system temp dir instead of a configurable dir, so this PR was to address that (among some others I made) |
@moufmouf Is there a good reason this does not use the cache instance provided via the constructor? This really caught me by surprise. |
@mdoelker yes, there is (unfortunately!) The cache for the annotation is a Doctrine Cache (that is not PSR-16 compatible, nor PSR-6 compatible). We could of course use an adapter to turn the Doctrine cache into a PSR-16 cache. The fact is that the PSR-16 cache is typically slower (if you look at the Symfony implementation, it needs to check if the key is valid according to PSR-16 rules, etc...). So it is solid, but I fear we would loose a few milliseconds here. Moreover, I don't want users to configure a remote cache (like Redis or a DB backed cache) for annotations. That would completely destroy the performances of GraphQLite. So the only 2 viable options are APCu and PHPFile cache. So I decided to hard code those in the SchemaFactory. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @MattBred ,
I'm 👍 on merging this once you move the $annotationCacheDir
parameter into a setter (see comment above)
Thanks a lot for your work!
src/SchemaFactory.php
Outdated
private $cacheNamespace; | ||
|
||
public function __construct(CacheInterface $cache, ContainerInterface $container) | ||
public function __construct(CacheInterface $cache, ContainerInterface $container, ?string $annotationCacheDir = null) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@MattBred Would you mind moving the $annotationCacheDir
parameter into a setter?
The SchemaFactory
class is typically following the "builder" pattern and any non compulsory parameter is configured via a setter.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds good, I will take care of that today
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@moufmouf Updated
Thanks for the explanation and for proceeding with this. Btw, does it make sense to check the $cache = function_exists('apcu_enabled') && apcu_enabled() ? new ApcuCache() : new PhpFileCache($cacheDir . '/graphqlite.' . crc32(__DIR__));
|
@moufmouf Have a look now, should be good to go? |
Excellent! Thanks a lot for your contribution! |
Addresses #309