8000 [Serializer] add a local cache to CacheClassMetadataFactory by bendavies · Pull Request #28457 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[Serializer] add a local cache to CacheClassMetadataFactory #28457

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 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
add a local cache to CacheClassMetadataFactory
  • Loading branch information
bendavies committed Sep 13, 2018
commit aa6509c60339aa311bc44d30220287b8c659db6c
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ class CacheClassMetadataFactory implements ClassMetadataFactoryInterface
*/
private $cacheItemPool;

private $localCache = array();

public function __construct(ClassMetadataFactoryInterface $decorated, CacheItemPoolInterface $cacheItemPool)
{
$this->decorated = $decorated;
Expand All @@ -47,15 +49,19 @@ public function getMetadataFor($value)
// Key cannot contain backslashes according to PSR-6
$key = strtr($class, '\\', '_');

if (array_key_exists($key, $this->localCache)) {
return $this->localCache[$key];
}

$item = $this->cacheItemPool->getItem($key);
if ($item->isHit()) {
return $item->get();
return $this->localCache[$key] = $item->get();
}

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

return $metadata;
return $this->localCache[$key] = $metadata;
}

/**
Expand Down
0