Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit cdaebf6

Browse filesBrowse files
minor #35079 [Serializer] add array cache in front of serializer cache (bastnic)
This PR was merged into the 5.1-dev branch. Discussion ---------- [Serializer] add array cache in front of serializer cache | Q | A | ------------- | --- | Branch? | master | Bug fix? | performance | New feature? | ... | Deprecations? | no | Tickets | #35041 | License | MIT | Doc PR | This is another implementation of #35041, after #35046. The DI solution is cleaner, but 10ms slower on my scenario (13 vs 3) and this data is not supposed to change at all (even in the original method there is a local cache). Diff from master (without warmup): ![image](https://user-images.githubusercontent.com/84887/71313592-2cb5be00-243b-11ea-8983-b30abb7d0698.png) Diff form master (with warmup): ![image](https://user-images.githubusercontent.com/84887/71313633-8e762800-243b-11ea-8044-003c810d3c0b.png) Diff from #35046: ![image](https://user-images.githubusercontent.com/84887/71313668-312ea680-243c-11ea-9768-8531f4f33f3c.png) Ping @nicolas-grekas Commits ------- 6ee306b [Cache] add array cache in front of serializer cache
2 parents 4e5b153 + 6ee306b commit cdaebf6
Copy full SHA for cdaebf6

File tree

Expand file treeCollapse file tree

1 file changed

+9
-2
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+9
-2
lines changed

‎src/Symfony/Component/Serializer/Mapping/Factory/CacheClassMetadataFactory.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Serializer/Mapping/Factory/CacheClassMetadataFactory.php
+9-2Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ class CacheClassMetadataFactory implements ClassMetadataFactoryInterface
3232
*/
3333
private $cacheItemPool;
3434

35+
private $loadedClasses = [];
36+
3537
public function __construct(ClassMetadataFactoryInterface $decorated, CacheItemPoolInterface $cacheItemPool)
3638
{
3739
$this->decorated = $decorated;
@@ -44,18 +46,23 @@ public function __construct(ClassMetadataFactoryInterface $decorated, CacheItemP
4446
public function getMetadataFor($value)
4547
{
4648
$class = $this->getClass($value);
49+
50+
if (isset($this->loadedClasses[$class])) {
51+
return $this->loadedClasses[$class];
52+
}
53+
4754
// Key cannot contain backslashes according to PSR-6
4855
$key = strtr($class, '\\', '_');
4956

5057
$item = $this->cacheItemPool->getItem($key);
5158
if ($item->isHit()) {
52-
return $item->get();
59+
return $this->loadedClasses[$class] = $item->get();
5360
}
5461

5562
$metadata = $this->decorated->getMetadataFor($value);
5663
$this->cacheItemPool->save($item->set($metadata));
5764

58-
return $metadata;
65+
return $this->loadedClasses[$class] = $metadata;
5966
}
6067

6168
/**

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.