Skip to content
Merged
Show file tree
Hide file tree
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
16 changes: 8 additions & 8 deletions src/Metadata/Property/Factory/CachedPropertyMetadataFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ final class CachedPropertyMetadataFactory implements PropertyMetadataFactoryInte

private $cacheItemPool;
private $decorated;
private $memoryCache = [];
private $localCache = [];

public function __construct(CacheItemPoolInterface $cacheItemPool, PropertyMetadataFactoryInterface $decorated)
{
Expand All @@ -41,18 +41,18 @@ public function __construct(CacheItemPoolInterface $cacheItemPool, PropertyMetad
*/
public function create(string $resourceClass, string $property, array $options = []): PropertyMetadata
{
$localKey = serialize([$resourceClass, $property, $options]);
if (isset($this->memoryCache[$localKey])) {
return $this->memoryCache[$localKey];
$localCacheKey = serialize([$resourceClass, $property, $options]);
if (isset($this->localCache[$localCacheKey])) {
return $this->localCache[$localCacheKey];
}

$cacheKey = self::CACHE_KEY_PREFIX.md5($localKey);
$cacheKey = self::CACHE_KEY_PREFIX.md5($localCacheKey);

try {
$cacheItem = $this->cacheItemPool->getItem($cacheKey);

if ($cacheItem->isHit()) {
return $this->memoryCache[$localKey] = $cacheItem->get();
return $this->localCache[$localCacheKey] = $cacheItem->get();
}
} catch (CacheException $e) {
// do nothing
Expand All @@ -61,12 +61,12 @@ public function create(string $resourceClass, string $property, array $options =
$propertyMetadata = $this->decorated->create($resourceClass, $property, $options);

if (!isset($cacheItem)) {
return $this->memoryCache[$localKey] = $propertyMetadata;
return $this->localCache[$localCacheKey] = $propertyMetadata;
}

$cacheItem->set($propertyMetadata);
$this->cacheItemPool->save($cacheItem);

return $this->memoryCache[$localKey] = $propertyMetadata;
return $this->localCache[$localCacheKey] = $propertyMetadata;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ final class CachedPropertyNameCollectionFactory implements PropertyNameCollectio

private $cacheItemPool;
private $decorated;
private $memoryCache = [];
private $localCache = [];

public function __construct(CacheItemPoolInterface $cacheItemPool, PropertyNameCollectionFactoryInterface $decorated)
{
Expand All @@ -41,18 +41,18 @@ public function __construct(CacheItemPoolInterface $cacheItemPool, PropertyNameC
*/
public function create(string $resourceClass, array $options = []): PropertyNameCollection
{
$localKey = serialize([$resourceClass, $options]);
if (isset($this->memoryCache[$localKey])) {
return $this->memoryCache[$localKey];
$localCacheKey = serialize([$resourceClass, $options]);
if (isset($this->localCache[$localCacheKey])) {
return $this->localCache[$localCacheKey];
}

$cacheKey = self::CACHE_KEY_PREFIX.md5($localKey);
$cacheKey = self::CACHE_KEY_PREFIX.md5($localCacheKey);

try {
$cacheItem = $this->cacheItemPool->getItem($cacheKey);

if ($cacheItem->isHit()) {
return $this->memoryCache[$localKey] = $cacheItem->get();
return $this->localCache[$localCacheKey] = $cacheItem->get();
}
} catch (CacheException $e) {
// do nothing
Expand All @@ -61,12 +61,12 @@ public function create(string $resourceClass, array $options = []): PropertyName
$propertyNameCollection = $this->decorated->create($resourceClass, $options);

if (!isset($cacheItem)) {
return $this->memoryCache[$localKey] = $propertyNameCollection;
return $this->localCache[$localCacheKey] = $propertyNameCollection;
}

$cacheItem->set($propertyNameCollection);
$this->cacheItemPool->save($cacheItem);

return $this->memoryCache[$localKey] = $propertyNameCollection;
return $this->localCache[$localCacheKey] = $propertyNameCollection;
}
}
12 changes: 6 additions & 6 deletions src/Metadata/Resource/Factory/CachedResourceMetadataFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ final class CachedResourceMetadataFactory implements ResourceMetadataFactoryInte

private $cacheItemPool;
private $decorated;
private $memoryCache = [];
private $localCache = [];

public function __construct(CacheItemPoolInterface $cacheItemPool, ResourceMetadataFactoryInterface $decorated)
{
Expand All @@ -41,8 +41,8 @@ public function __construct(CacheItemPoolInterface $cacheItemPool, ResourceMetad
*/
public function create(string $resourceClass): ResourceMetadata
{
if (isset($this->memoryCache[$resourceClass])) {
return $this->memoryCache[$resourceClass];
if (isset($this->localCache[$resourceClass])) {
return $this->localCache[$resourceClass];
}

$cacheKey = self::CACHE_KEY_PREFIX.md5($resourceClass);
Expand All @@ -51,7 +51,7 @@ public function create(string $resourceClass): ResourceMetadata
$cacheItem = $this->cacheItemPool->getItem($cacheKey);

if ($cacheItem->isHit()) {
return $this->memoryCache[$resourceClass] = $cacheItem->get();
return $this->localCache[$resourceClass] = $cacheItem->get();
}
} catch (CacheException $e) {
// do nothing
Expand All @@ -60,12 +60,12 @@ public function create(string $resourceClass): ResourceMetadata
$resourceMetadata = $this->decorated->create($resourceClass);

if (!isset($cacheItem)) {
return $this->memoryCache[$resourceClass] = $resourceMetadata;
return $this->localCache[$resourceClass] = $resourceMetadata;
}

$cacheItem->set($resourceMetadata);
$this->cacheItemPool->save($cacheItem);

return $this->memoryCache[$resourceClass] = $resourceMetadata;
return $this->localCache[$resourceClass] = $resourceMetadata;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ final class CachedResourceNameCollectionFactory implements ResourceNameCollectio

private $cacheItemPool;
private $decorated;
private $memoryCache = [];
private $localCache = [];

public function __construct(CacheItemPoolInterface $cacheItemPool, ResourceNameCollectionFactoryInterface $decorated)
{
Expand All @@ -41,15 +41,15 @@ public function __construct(CacheItemPoolInterface $cacheItemPool, ResourceNameC
*/
public function create(): ResourceNameCollection
{
if (isset($this->memoryCache[self::CACHE_KEY])) {
return $this->memoryCache[self::CACHE_KEY];
if (isset($this->localCache[self::CACHE_KEY])) {
return $this->localCache[self::CACHE_KEY];
}

try {
$cacheItem = $this->cacheItemPool->getItem(self::CACHE_KEY);

if ($cacheItem->isHit()) {
return $this->memoryCache[self::CACHE_KEY] = $cacheItem->get();
return $this->localCache[self::CACHE_KEY] = $cacheItem->get();
}
} catch (CacheException $e) {
// do nothing
Expand All @@ -58,12 +58,12 @@ public function create(): ResourceNameCollection
$resourceNameCollection = $this->decorated->create();

if (!isset($cacheItem)) {
return $this->memoryCache[self::CACHE_KEY] = $resourceNameCollection;
return $this->localCache[self::CACHE_KEY] = $resourceNameCollection;
}

$cacheItem->set($resourceNameCollection);
$this->cacheItemPool->save($cacheItem);

return $this->memoryCache[self::CACHE_KEY] = $resourceNameCollection;
return $this->localCache[self::CACHE_KEY] = $resourceNameCollection;
}
}