Fixed exception in caching mechanism, if no user was logged in.

This commit is contained in:
Jan Böhmer 2019-08-20 18:18:11 +02:00
parent 1445d7475a
commit 8e23629dc0
4 changed files with 91 additions and 17 deletions

View file

@ -36,6 +36,7 @@ use App\Entity\Base\DBElement;
use App\Entity\Base\StructuralDBElement;
use App\Entity\UserSystem\Group;
use App\Entity\UserSystem\User;
use App\Services\UserCacheKeyGenerator;
use Doctrine\ORM\Event\LifecycleEventArgs;
use Doctrine\ORM\Event\PostFlushEventArgs;
use Doctrine\ORM\Event\PreFlushEventArgs;
@ -45,10 +46,12 @@ use Symfony\Contracts\Cache\TagAwareCacheInterface;
class TreeCacheInvalidationListener
{
protected $cache;
protected $keyGenerator;
public function __construct(TagAwareCacheInterface $treeCache)
public function __construct(TagAwareCacheInterface $treeCache, UserCacheKeyGenerator $keyGenerator)
{
$this->cache = $treeCache;
$this->keyGenerator = $keyGenerator;
}
/**
@ -69,7 +72,7 @@ class TreeCacheInvalidationListener
//If a user change, then invalidate all cached trees for him
if ($element instanceof User) {
$tag = "user_" . $element->getUsername();
$tag = $this->keyGenerator->generateKey($element);
$this->cache->invalidateTags([$tag]);
}