Skip to content
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

Merged

Conversation

TheCelavi
Copy link
Contributor

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.

@@ -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'])) {
Copy link
Contributor Author

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...

Copy link
Member

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.

@@ -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(
Copy link
Contributor Author

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...

@TheCelavi
Copy link
Contributor Author

@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
Copy link
Member

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"?

Copy link
Contributor Author

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

Copy link
Member

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'];
Copy link
Member

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

'.annotations.cache',
0777 & (~$options['cacheFileMode'])
);
}
Copy link
Member

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.

Copy link
Member

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:

  1. To extend GoAopContainer class and to redefine definition of annotation.reader class.
  2. 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 simple FilesystemCache cached reader.

@@ -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'])) {
Copy link
Member

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) {

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) {

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();
Copy link
Contributor Author

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) {
Copy link
Contributor Author

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.

Copy link
Member

@lisachenko lisachenko left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good now

@lisachenko lisachenko changed the title Fix for #136, #358 and #245 [Fix] Introduce an option to configure cached reader for annotations #136, #358 and #245 Aug 29, 2017
@lisachenko lisachenko added this to the 2.x milestone Aug 29, 2017
@lisachenko lisachenko merged commit 2411eea into goaop:2.x Aug 29, 2017
@paventuri
Copy link

Is this going to be merged into goaop:1.X too?

@lisachenko
Copy link
Member

lisachenko commented Aug 30, 2017

@paventuri unfortunately, no, versions 1.x are no maintained anymore. Consider to upgrade to 2.x

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

4 participants