Skip to content

[PropertyInfo] Cache support #16917

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

Closed
wants to merge 6 commits into from
Closed

Conversation

dunglas
Copy link
Member

@dunglas dunglas commented Dec 9, 2015

Q A
Bug fix? no
New feature? yes
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets #16893
License MIT
Doc PR todo

Replace #16893 with several advantages:

@dunglas dunglas force-pushed the property_info_cache branch from 22c5ede to 3d15937 Compare December 9, 2015 07:20
@dunglas dunglas changed the title [PropertInfo] Cache support [PropertyInfo] Cache support Dec 9, 2015
@dunglas dunglas force-pushed the property_info_cache branch 2 times, most recently from 3d7efb2 to 677b45d Compare December 9, 2015 07:23
{
$this->listExtractors = $listExtractors;
$this->typeExtractors = $typeExtractors;
$this->descriptionExtractors = $descriptionExtractors;
$this->accessExtractors = $accessExtractors;
$this->cache = $cache;
Copy link
Contributor

Choose a reason for hiding this comment

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

instead of passing the cache here I would prefer using composition instead which decorate the default PropertyInfoExtractor something like https://gist.github.com/aitboudad/12419c2db6d19320c5fa

Copy link
Contributor

Choose a reason for hiding this comment

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

same thing for #16838

Copy link
Contributor

Choose a reason for hiding this comment

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

👍

Copy link
Member Author

Choose a reason for hiding this comment

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

I was thinking the same thing initially, but finally I'm not sure that it's a good idea:

  • Performance (and cache) is not an "optional" feature. It should be enable for all implementations in prod and IMO it's why it belongs to this class.
  • In the context of the Standard Edition it adds a lot of complexity and an overhead: it requires to use the service decorator feature to switch the class depending of the environment (the cache must be enabled in prod, but not in dev)
  • In the context of the component, it makes it harder to enable the cache (one more class to instantiate)
  • all other components using cache doesn't use composition for that (it is considered as a builtin feature)

When the PSR-6 will be ready, the argument can even be made mandatory (it's better to always use a cache) and a NullCache or something like that can be added for the dev environment (like with the Logger).

What do you think @symfony/deciders?

Copy link
Contributor

Choose a reason for hiding this comment

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

👍 Composition is much cleaner and should be used unless it is not possible, like with the property accessor cache.

@dunglas
Copy link
Member Author

dunglas commented Dec 9, 2015

Switched to an implementation to a Decorator as requested. Should the decorator belong to the Doctrine Bridge? IMO no because when PSR-6 will be ready we will switch to this interface instead of Doctrine Cache but I'm open to suggestions. Same if you find a better name for the decorator.

@dunglas
Copy link
Member Author

dunglas commented Dec 14, 2015

ping @symfony/deciders

}

/**
* Retrieves the cached data if applicable or delegates to the decorated extractor..
Copy link
Member

Choose a reason for hiding this comment

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

double dots

@xabbuh
Copy link
Member

xabbuh commented Dec 15, 2015

Looks like you need to rebase here (the namespace changes have been done in another PR).

@dunglas dunglas force-pushed the property_info_cache branch from 3ed99f3 to 436f650 Compare December 16, 2015 07:31
@dunglas
Copy link
Member Author

dunglas commented Dec 16, 2015

Rebased and typo fixed.

*/
private function extract($method, array $arguments)
{
$key = $method.serialize($arguments);
Copy link
Member

Choose a reason for hiding this comment

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

just wondering: $arguments contains $context. But what does $context contain? Is it a big or small array of scalars? Something potentially non-serializable there?

Copy link
Member Author

Choose a reason for hiding this comment

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

For now it is only used in Symfony by the serializer extractor (a small array of strings). But it's a good concern because the context can be used by any custom extractor and can contain anything.

Do you know a way to easily retrieve an unique identifier from an array or should we try something like recursively replacing instances of objects by the return of spl_object_hash()?

Copy link
Member Author

Choose a reason for hiding this comment

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

Maybe can we add a note in the doc of $context in interfaces that it should only contain scalar and serializable objects or it will create unexpected side effects?

It will avoid to add a costly (in term of performance) custom serialization process here.

@dunglas
Copy link
Member Author

dunglas commented Dec 31, 2015

Committed a better way to handle context not serializable. /cc @nicolas-grekas

use Doctrine\Common\Cache\Cache;

/**
* Adds a cache layer on top of an extractor.
Copy link
Member

Choose a reason for hiding this comment

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

This is not really meaningful.

@dunglas
Copy link
Member Author

dunglas commented Jan 18, 2016

Status: needs work

Should be ported to PSR-6

@dunglas dunglas force-pushed the property_info_cache branch from bd1022c to 335381b Compare January 26, 2016 12:06
@dunglas dunglas force-pushed the property_info_cache branch from 335381b to 9396a19 Compare January 26, 2016 12:07
@dunglas
Copy link
Member Author

dunglas commented Jan 26, 2016

Status: Needs review

Moved to PSR-6.

@@ -34,6 +35,7 @@
"phpdocumentor/reflection": "<1.0.7"
},
"suggest": {
"symfony/cache": "To cache results",
Copy link
Member

Choose a reason for hiding this comment

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

"psr/cache-implementation": "For using the metadata cache.",?

@dunglas
Copy link
Member Author

dunglas commented Jan 26, 2016

@fabpot symfony/cache replaced by psr/cache-implementation in suggest.

@fabpot
Copy link
Member

fabpot commented Jan 27, 2016

Thank you @dunglas.

@fabpot fabpot closed this Jan 27, 2016
fabpot added a commit that referenced this pull request Jan 27, 2016
This PR was squashed before being merged into the 3.1-dev branch (closes #16917).

Discussion
----------

[PropertyInfo] Cache support

| Q             | A
| ------------- | ---
| Bug fix?      | no
| New feature?  | yes
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #16893
| License       | MIT
| Doc PR        | todo

Replace #16893 with several advantages:

- Less complex patch
- Work for all usages of PropertyInfo (even outside of the Serializer)
- Avoid a circular reference between Serializer's CallMetadataFactory and PropertyInfo's SerializerExtractor
- Allow @mihai-stancu's #16143 to work as-is

Commits
-------

86c20df [PropertyInfo] Cache support
@dunglas dunglas deleted the property_info_cache branch January 27, 2016 07:12
*/
class PropertyInfoCacheExtractorTest extends AbstractPropertyInfoExtractorTest
{
public function setUp()
Copy link
Contributor

Choose a reason for hiding this comment

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

setUp is a protected method

Copy link
Contributor

Choose a reason for hiding this comment

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

Quick search revealed there's few more occurrences. I'll send a PR to fix them.

@fabpot fabpot mentioned this pull request May 13, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants