Exemplo n.º 1
0
 /**
  * Creates the cache ID for a renderable element.
  *
  * Creates the cache ID string based on #cache['keys'] + #cache['contexts'].
  *
  * @param array $elements
  *   A renderable array.
  *
  * @return string
  *   The cache ID string, or FALSE if the element may not be cached.
  */
 protected function createCacheID(array $elements)
 {
     // If the maximum age is zero, then caching is effectively prohibited.
     if (isset($elements['#cache']['max-age']) && $elements['#cache']['max-age'] === 0) {
         return FALSE;
     }
     if (isset($elements['#cache']['keys'])) {
         $cid_parts = $elements['#cache']['keys'];
         if (!empty($elements['#cache']['contexts'])) {
             $contexts = $this->cacheContextsManager->convertTokensToKeys($elements['#cache']['contexts']);
             $cid_parts = array_merge($cid_parts, $contexts);
         }
         return implode(':', $cid_parts);
     }
     return FALSE;
 }
Exemplo n.º 2
0
 /**
  * @covers ::convertTokensToKeys
  *
  * @expectedException \Exception
  *
  * @dataProvider providerTestInvalidCalculatedContext
  */
 public function testInvalidCalculatedContext($context_token)
 {
     $container = $this->getMockContainer();
     $cache_contexts_manager = new CacheContextsManager($container, $this->getContextsFixture());
     $cache_contexts_manager->convertTokensToKeys([$context_token]);
 }