diff --git a/nur_src/b/io/CacheManager.php b/nur_src/b/io/CacheManager.php index 547a854..958bbcc 100644 --- a/nur_src/b/io/CacheManager.php +++ b/nur_src/b/io/CacheManager.php @@ -23,13 +23,13 @@ class CacheManager { * @var array tableau {id => cache} indiquant si l'élément id doit être mis en * cache */ - protected $caches; + protected array $caches; /** * @var bool valeur par défaut de cache si la valeur n'est pas trouvée dans * $caches */ - protected $defaultCache; + protected bool $defaultCache; /** * @var array|null groupes à toujours inclure dans le cache. pour les @@ -38,13 +38,13 @@ class CacheManager { * * $excludes est prioritaire par rapport à $includes */ - protected $includes; + protected ?array $includes; /** * @var array|null groupes à exclure de la mise en cache. la mise en cache est * toujours calculée pour les identifiants de ces groupes. */ - protected $excludes; + protected ?array $excludes; function setNoCache(bool $noCache=true, bool $reset=true): self { if ($reset) $this->caches = []; @@ -53,11 +53,13 @@ class CacheManager { } function shouldCache(string $id, ?string $groupId=null, bool $reset=true): bool { - $includes = $this->includes; - $shouldInclude = $includes !== null && in_array($groupId, $includes); - $excludes = $this->excludes; - $shouldExclude = $excludes !== null && in_array($groupId, $excludes); - if ($shouldInclude && !$shouldExclude) return true; + if ($groupId !== null) { + $includes = $this->includes; + $shouldInclude = $includes !== null && in_array($groupId, $includes); + $excludes = $this->excludes; + $shouldExclude = $excludes !== null && in_array($groupId, $excludes); + if ($shouldInclude && !$shouldExclude) return true; + } $cache = A::get($this->caches, $id, $this->defaultCache); $this->caches[$id] = $reset?: $cache; return $cache;