mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2025-07-05 07:54:35 +02:00
Fixed exception in caching mechanism, if no user was logged in.
This commit is contained in:
parent
1445d7475a
commit
8e23629dc0
4 changed files with 91 additions and 17 deletions
|
@ -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]);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue