-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Cache] Add PhpArrayAdapter to use shared memory on PHP 7.0 #18823
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
|
||
if ('N;' === $value) { | ||
$value = null; | ||
} elseif (isset($value[2]) && is_string($value) && ':' === $value[1]) { |
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_string
should come before isset($value[2])
IMO
1f8c746
to
d9328e2
Compare
} | ||
} | ||
|
||
$dump = <<<EOF |
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 should be enclosed with nowdoc instead of heredoc.
*/ | ||
class NullAdapter implements AdapterInterface | ||
{ | ||
private $createCacheItem; |
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.
phpdoc missing
928dc61
to
c6e08fc
Compare
I did the changes |
EOF; | ||
|
||
foreach ($values as $key => $value) { | ||
CacheItem::validateKey($key); |
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.
because PHP casts numeric string keys to ints, we should cast ints to string here:
`is_int($key) ? (string) $key : $key);
$fallbackKeys = array(); | ||
|
||
foreach ($keys as $key) { | ||
if (!is_string($key)) { |
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 check should be done before calling generateItems
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.
indeed. Doing it in the generator will throw the exception too late (the iterator will throw it during iteration, while it must be throw by getItems)
I suggest renaming this adapter to Php7Adapter (ans use the OpcacheAdapter name in #18894) |
I did some benchmarks to check the PHP 5.6 support in this PR. I used three Docker containers with only PHP/HHVM installed, on the same host. I used Apache Benchmark with 1000 requests at a concurrency of 100 ( The results are the following:
This seems to indicate that having an array filled with data in PHP 5.6 is significantly slower than having an empty array. Therefore, I removed the PHP 5.6 support for this PhpArrayAdapter in the |
4db11cd
to
198e04c
Compare
👍 |
bb8e068
to
c507cc0
Compare
👍 |
try { | ||
$value = serialize($value); | ||
} catch (\Exception $e) { | ||
throw new InvalidArgumentException(sprintf('Cache key "%s has non-serializable %s value', $key, get_class($value)), 0, $e); |
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.
Missing closing double quote.
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.
Also missing a dot at the end.
c507cc0
to
4ecde9d
Compare
I did the changes. |
private $fallbackPool; | ||
|
||
/** | ||
* @param string $file The PHP file were values are cached. |
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.
4ecde9d
to
28a40d2
Compare
I did the change |
Thank you @tgalopin. |
…P 7.0 (tgalopin) This PR was merged into the 3.2-dev branch. Discussion ---------- [Cache] Add PhpArrayAdapter to use shared memory on PHP 7.0 | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | yes | BC breaks? | no | Deprecations? | no | Tests pass? | WIP | Fixed tickets | - | License | MIT | Doc PR | - Depends on #18825 This PR aims to implement a Symfony Cache adapter able to build files optimized for OPCache memory storage. Any kind of static data that can be warmed up is a candidate for OPcache storage. This PR is limited to the implementation of the Adapter. It's usage in the annotations caching system is implemented in the PR #18533. The aim is also to use this adapter in other contexts (validator, serializer, ...). Commits ------- 28a40d2 [Cache] Add PhpArrayAdapter to use shared memory on PHP 7.0+
…e warmer for annotations (tgalopin) This PR was squashed before being merged into the 3.2-dev branch (closes #18533). Discussion ---------- [FrameworkBundle] Wire PhpArrayAdapter with a new cache warmer for annotations | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | yes | BC breaks? | no | Deprecations? | no | Tests pass? | WIP | Fixed tickets | - | License | MIT | Doc PR | - Depends on #18825 and #18823 This PR implements the usage of the new OpCacheAdapter in the annotations caching system. The idea to use this adapter as much as possible in Symfony (validator, serializer, ...). These other implementations will be the object of different PRs. Commits ------- f950a2b [FrameworkBundle] Wire PhpArrayAdapter with a new cache warmer for annotations
…e warmer for annotations (tgalopin) This PR was squashed before being merged into the 3.2-dev branch (closes #18533). Discussion ---------- [FrameworkBundle] Wire PhpArrayAdapter with a new cache warmer for annotations | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | yes | BC breaks? | no | Deprecations? | no | Tests pass? | WIP | Fixed tickets | - | License | MIT | Doc PR | - Depends on symfony/symfony#18825 and symfony/symfony#18823 This PR implements the usage of the new OpCacheAdapter in the annotations caching system. The idea to use this adapter as much as possible in Symfony (validator, serializer, ...). These other implementations will be the object of different PRs. Commits ------- f950a2b [FrameworkBundle] Wire PhpArrayAdapter with a new cache warmer for annotations
…e warmer for annotations (tgalopin) This PR was squashed before being merged into the 3.2-dev branch (closes #18533). Discussion ---------- [FrameworkBundle] Wire PhpArrayAdapter with a new cache warmer for annotations | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | yes | BC breaks? | no | Deprecations? | no | Tests pass? | WIP | Fixed tickets | - | License | MIT | Doc PR | - Depends on symfony/symfony#18825 and symfony/symfony#18823 This PR implements the usage of the new OpCacheAdapter in the annotations caching system. The idea to use this adapter as much as possible in Symfony (validator, serializer, ...). These other implementations will be the object of different PRs. Commits ------- f950a2b [FrameworkBundle] Wire PhpArrayAdapter with a new cache warmer for annotations
…e warmer for annotations (tgalopin) This PR was squashed before being merged into the 3.2-dev branch (closes #18533). Discussion ---------- [FrameworkBundle] Wire PhpArrayAdapter with a new cache warmer for annotations | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | yes | BC breaks? | no | Deprecations? | no | Tests pass? | WIP | Fixed tickets | - | License | MIT | Doc PR | - Depends on symfony/symfony#18825 and symfony/symfony#18823 This PR implements the usage of the new OpCacheAdapter in the annotations caching system. The idea to use this adapter as much as possible in Symfony (validator, serializer, ...). These other implementations will be the object of different PRs. Commits ------- f950a2b [FrameworkBundle] Wire PhpArrayAdapter with a new cache warmer for annotations
…weaverryan) This PR was merged into the 3.2 branch. Discussion ---------- Covering two missing Cache adapters introduced in 3.2 Hi guys! These are 2 missing adapters that were introduced in 3.2! symfony/symfony#18894 and symfony/symfony#18823 Cheers! Commits ------- a3e69e2 Tweaks based on feedback! 1b6cb69 Covering two missing adapters introduced in 3.2
Depends on #18825
This PR aims to implement a Symfony Cache adapter able to build files optimized for OPCache memory storage. Any kind of static data that can be warmed up is a candidate for OPcache storage.
This PR is limited to the implementation of the Adapter. It's usage in the annotations caching system is implemented in the PR #18533. The aim is also to use this adapter in other contexts (validator, serializer, ...).