-
-
Notifications
You must be signed in to change notification settings - Fork 163
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
[Fix] Introduce an option to configure cached reader for annotations #136, #358 and #245 #359
[Fix] Introduce an option to configure cached reader for annotations #136, #358 and #245 #359
Conversation
src/Core/GoAspectContainer.php
Outdated
@@ -91,12 +91,11 @@ public function __construct() | |||
$this->share('aspect.annotation.reader', function(Container $container) { | |||
$options = $container->get('kernel.options'); | |||
$reader = new AnnotationReader(); | |||
if (!empty($options['cacheDir'])) { | |||
$reader = new FileCacheReader( | |||
if (!empty($options['annotationCache'])) { |
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.
I didn't fixed this one.
annotationCache
is not optional, however, current unit tests do not mocks engine configuration, so if I presume that annotationCache
will always exist here, test fails.
In general - if you want, I can deal with test as well and remove if (!empty(...)) here, however, both code and tests should be revised -> what is required and what is optional...
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.
It's ok to check with !empty($options['annotationCache'])
here.
src/Core/AspectKernel.php
Outdated
@@ -216,9 +216,9 @@ protected function normalizeOptions(array $options) | |||
$options['excludePaths'] = PathResolver::realpath($options['excludePaths']); | |||
|
|||
if (null === $options['annotationCache']) { | |||
$options['annotationCache'] = new PhpFileCache( | |||
$options['annotationCache'] = new FilesystemCache( |
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.
This is extremely stupid and I don't have any idea why this causing issues...
If Doctrine\Common\Cache\ PhpFileCache
is used, test fails (and it does not work in general) on PHP 5.x, and 7.0. It works on PHP 7.1 and 7.2.
On the other hand, with same settings, if Doctrine\Common\Cache\ FilesystemCache
is used, all test passes and it does work.
@lisachenko -> do you have any idea what is happening here? And how to proceed? Should we keep FilesystemCache
as default implementation, or? Version check and pick accordingly?
BTW I will report issue since it can be easily reproduced...
@paventuri In general, it could be implemented by adding some more logic into, per example, caching transformer. However, more logic make us maintain it. Maybe in the future, since, with possibility to choose annotation cache storage this issue may be considered as fixed... I don't know how Alexander feels about it... |
README.md
Outdated
#### 6.1 Custom annotation cache | ||
|
||
By default, Go! AOP uses `Doctrine\Common\Cache\PhpFileCache` for caching | ||
annotations. However, should you need to use any other caching engine |
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.
Is it ok to use "...should you need to use.." here? Maybe replace "should" with "if"?
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.
Mission impossible? "Your mission is, should you choose to accept it, ..." ? :D
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.
For my English knowledge it is strange phrase with "should" usage )) But we can ignore my comment.
My version is: "However if you need to use any other caching engine...". More straightforward ) But I can not be sure if your version isn't correct )
$options['excludePaths'][] = $options['cacheDir']; | ||
$options['excludePaths'][] = __DIR__ . '/../'; | ||
$options['appDir'] = PathResolver::realpath($options['appDir']); | ||
$options['cacheFileMode'] = (int) $options['cacheFileMode']; |
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.
There is a gotcha here, cacheFileMode
MUST be integer, otherwise strange effects occurs:
echo (int) '0770'; // Outputs 770
echo (int) 0770; // 504, which is correct
src/Core/AspectKernel.php
Outdated
'.annotations.cache', | ||
0777 & (~$options['cacheFileMode']) | ||
); | ||
} |
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.
In my opinion this should be done in GoAopContainer
class, kernel should not work with such classes directly.
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.
I can propose several solutions:
- To extend
GoAopContainer
class and to redefine definition of annotation.reader class. - Make annotation cache an option that accepts a closure that should return instance of annotation reader and then just store it in the container if declared. By default,
GoAopContainer
will define a closure that returns simpleFilesystemCache
cached reader.
src/Core/GoAspectContainer.php
Outdated
@@ -91,12 +91,11 @@ public function __construct() | |||
$this->share('aspect.annotation.reader', function(Container $container) { | |||
$options = $container->get('kernel.options'); | |||
$reader = new AnnotationReader(); | |||
if (!empty($options['cacheDir'])) { | |||
$reader = new FileCacheReader( | |||
if (!empty($options['annotationCache'])) { |
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.
It's ok to check with !empty($options['annotationCache'])
here.
@@ -88,20 +89,35 @@ public function __construct() | |||
); | |||
}); | |||
|
|||
$this->share('aspect.annotation.reader', function(Container $container) { | |||
$this->share('aspect.annotation.cache', function(Container $container) { |
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.
Expected 1 space after FUNCTION keyword; 0 found
}); | ||
|
||
$this->share('aspect.annotation.reader', function(Container $container) { |
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.
Expected 1 space after FUNCTION keyword; 0 found
); | ||
} | ||
|
||
return $reader; | ||
return new DoctrineCache\ArrayCache(); |
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.
This can occur when running unit tests, so I fallback to ArrayCache in order for tests to pass.
@@ -88,19 +89,35 @@ public function __construct() | |||
); | |||
}); | |||
|
|||
$this->share('aspect.annotation.reader', function(Container $container) { | |||
$this->share('aspect.annotation.cache', function(Container $container) { |
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.
Ok, so moving to container - agree, much better. Defined new service, aspect.annotation.cache
, so reader can get that service for cache engine for annotations.
Much better, thanks.
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.
Looks good now
Is this going to be merged into goaop:1.X too? |
@paventuri unfortunately, no, versions 1.x are no maintained anymore. Consider to upgrade to 2.x |
Fixes for several issues, mostly in regards to caching mechanism.
Added possibility for users to define custom cache driver for annotations, under option
annotationCache
. Any Doctrine cache can be used.