public function tryGet($hash) { if (!isset(self::$secondLevelCache[$hash])) { self::$secondLevelCache[$hash] = $this->cacheAdapter->tryGet($hash) ?: null; } $cachedValue = self::$secondLevelCache[$hash]; return $cachedValue instanceof IQuery ? $cachedValue : null; }
public function testThatCacheDoesNotGetValuesOutsideOfNamespace() { $this->cache->save('not-in-namespace', true); $this->assertSame($this->cache->tryGet('not-in-namespace'), true); $this->assertSame($this->namespacedCache->tryGet('not-in-namespace'), null); }
protected function loadCompiledQueryFromTemplate(Caching\ICacheAdapter $queryCache, $templateHash, IQueryTemplate $template, Queries\IResolvedParameterRegistry $parameters, callable $compileRequestCallback) { if ($template instanceof IStaticQueryTemplate) { return $template->getCompiledQuery(); } $resolvedStructuralParameters = $template->resolveStructuralParameters($parameters, $hash); $compiledQueryHash = md5($templateHash . '-' . $hash); $compiledQuery = $queryCache->tryGet($compiledQueryHash); if (!$compiledQuery instanceof ICompiledQuery) { $compiledQuery = $compileRequestCallback($template, $resolvedStructuralParameters); $queryCache->save($compiledQueryHash, $compiledQuery); } return $compiledQuery; }