Skip to content

Commit

Permalink
[Cache] cache improvements - decorate Pimcore CoreCacheHandler
Browse files Browse the repository at this point in the history
  • Loading branch information
dpfaffenbauer committed Oct 20, 2023
1 parent 5cf61f1 commit 140d2c5
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
18 changes: 9 additions & 9 deletions src/CoreShop/Behat/Context/Domain/CacheContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,22 +82,22 @@ public function theCacheItemSerializedShouldLookLikeTheKnownOne(CacheItem $cache
$itemData = serialize($itemData);
}

$unserializedNull = unserialize($itemData, ['allowed_classes' => false]);
$serializedNull = unserialize($itemData, ['allowed_classes' => false]);

function convertToStdClass(\__PHP_Incomplete_Class $object)
$convertToStdClass = static function(\__PHP_Incomplete_Class $object)
{
$fixKey = function ($matches) {
return ":".strlen($matches[1]).":\"".$matches[1]."\"";
};

$dump = serialize($object);
$dump = preg_replace('/^O:\d+:"[^"]++"/', 'O:8:"stdClass"', $dump);
$dump = preg_replace_callback('/:\d+:"\0.*?\0([^"]+)"/', $fixKey, $dump);
$dump = preg_replace_callback(
'/:\d+:"\0.*?\0([^"]+)"/',
static fn($matches) => ":".strlen($matches[1]).":\"".$matches[1]."\"",
$dump
);

return unserialize($dump);
}
};

$stdClass = convertToStdClass($unserializedNull);
$stdClass = $convertToStdClass($serializedNull);

$cacheValue = $stdClass->{$property};

Expand Down
3 changes: 2 additions & 1 deletion src/CoreShop/Behat/Context/Setup/CacheContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ public function iCacheObjectWithKey(mixed $object, string $key): void
{
if ($object instanceof Concrete) {
Cache::getHandler()->removeClearedTags(['object_'.$object->getId()]);
}
Cache::getHandler()->removeClearedTags(['cs_'.$object->getClassId()]);
}

Assert::true(Cache::getHandler()->save($key, $object, ['behat'], null, 0, true));

Expand Down

0 comments on commit 140d2c5

Please sign in to comment.