Skip to content

Commit

Permalink
Fixed doctrine cache
Browse files Browse the repository at this point in the history
  • Loading branch information
tg666 committed Jan 6, 2023
1 parent 6bf1d08 commit a7b141f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
],
"require": {
"php": "^7.1 || ^8.1",
"doctrine/orm": "^2.7",
"doctrine/orm": "^2.11",
"behat/transliterator": "^1.2"
},
"require-dev": {
Expand Down
14 changes: 8 additions & 6 deletions src/DefinitionStorage/AnnotationSluggableDefinitionStorage.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public function __construct(Doctrine\Common\Annotations\Reader $reader)
* {@inheritDoc}
*
* @throws Doctrine\ORM\Mapping\MappingException
* @throws \Psr\Cache\InvalidArgumentException
* @throws \ReflectionException
*/
public function findSluggableDefinitions(Doctrine\ORM\EntityManagerInterface $em, string $entityClassName): array
Expand All @@ -38,19 +39,19 @@ public function findSluggableDefinitions(Doctrine\ORM\EntityManagerInterface $em
return $this->definitionStorage[$name];
}

/** @var \Doctrine\Common\Cache\Cache|NULL $cache */
$cache = $em->getMetadataFactory()->getCacheDriver();
$cache = $em->getConfiguration()->getMetadataCache();
$cacheItem = $cache ? $cache->getItem($name) : NULL;

if (NULL !== $cache && $cache->contains($name)) {
return $this->definitionStorage[$name] = unserialize($cache->fetch($name), [
if (NULL !== $cacheItem && $cacheItem->isHit()) {
return $this->definitionStorage[$name] = unserialize($cacheItem->get(), [
'allowed_classes' => TRUE,
]);
}

$this->definitionStorage[$name] = $this->createSluggableDefinitions($metadata);

if (NULL !== $cache) {
$cache->save($name, serialize($this->definitionStorage[$name]));
if (NULL !== $cacheItem) {
$cacheItem->set(serialize($this->definitionStorage[$name]));
}

return $this->definitionStorage[$name];
Expand All @@ -61,6 +62,7 @@ public function findSluggableDefinitions(Doctrine\ORM\EntityManagerInterface $em
*
* @throws Doctrine\ORM\Mapping\MappingException
* @throws \ReflectionException
* @throws \Psr\Cache\InvalidArgumentException
*/
public function getSluggableDefinition(Doctrine\ORM\EntityManagerInterface $em, string $entityClassName, string $fieldName): SixtyEightPublishers\DoctrineSluggable\Definition\SluggableDefinition
{
Expand Down

0 comments on commit a7b141f

Please sign in to comment.