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

Add metadata caching #469

Merged
merged 1 commit into from
Mar 19, 2016
Merged

Conversation

teohhanhui
Copy link
Contributor

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

Add PSR6 cached decorators for all metadata factories.

Also provide symfony/cache integration in the Symfony bundle.

@teohhanhui
Copy link
Contributor Author

I easily get more than 10x performance improvement on a collection get of 30 items.

@teohhanhui teohhanhui force-pushed the metadata-cache branch 3 times, most recently from 0d61a40 to e935bf3 Compare March 18, 2016 16:56
*/
public function create(string $resourceClass, array $options = []) : PropertyNameCollection
{
$cacheKey = self::CACHE_KEY_PREFIX.md5(json_encode([$resourceClass, $options]));
Copy link
Member

Choose a reason for hiding this comment

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

serialize is faster.

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 gave that some thought too, but json_encode produces shorter output. We could always improve on this later on if the performance difference is substantive?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Switched to sha1 since it's (surprisingly) faster than md5 (at least that's what openssl speed md5 sha1 shows on my machine and a Digital Ocean droplet).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oops, that's not the case in PHP. Let's switch back to md5.

@dunglas
Copy link
Member

dunglas commented Mar 18, 2016

👍 except for the last comment I made. Good job thank you very much!!

@teohhanhui teohhanhui force-pushed the metadata-cache branch 6 times, most recently from 518fd6d to 16cb4f8 Compare March 19, 2016 09:09
@teohhanhui
Copy link
Contributor Author

ping @api-platform/core-team

dunglas added a commit that referenced this pull request Mar 19, 2016
@dunglas dunglas merged commit 790ebd1 into api-platform:master Mar 19, 2016
@dunglas
Copy link
Member

dunglas commented Mar 19, 2016

Thank you @teohhanhui

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

Successfully merging this pull request may close these issues.

2 participants