当前位置: 首页>>代码示例>>PHP>>正文


PHP Cache::mergeMaxAges方法代码示例

本文整理汇总了PHP中Drupal\Core\Cache\Cache::mergeMaxAges方法的典型用法代码示例。如果您正苦于以下问题:PHP Cache::mergeMaxAges方法的具体用法?PHP Cache::mergeMaxAges怎么用?PHP Cache::mergeMaxAges使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Drupal\Core\Cache\Cache的用法示例。


在下文中一共展示了Cache::mergeMaxAges方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: merge

 /**
  * Merges the values of another bubbleable metadata object with this one.
  *
  * @param \Drupal\Core\Render\BubbleableMetadata $other
  *   The other bubbleable metadata object.
  * @return static
  *   A new bubbleable metadata object, with the merged data.
  *
  * @todo Add unit test for this in
  *       \Drupal\Tests\Core\Render\BubbleableMetadataTest when
  *       drupal_merge_attached() no longer is a procedural function and remove
  *       the '@codeCoverageIgnore' annotation.
  */
 public function merge(BubbleableMetadata $other)
 {
     $result = new BubbleableMetadata();
     $result->contexts = Cache::mergeContexts($this->contexts, $other->contexts);
     $result->tags = Cache::mergeTags($this->tags, $other->tags);
     $result->maxAge = Cache::mergeMaxAges($this->maxAge, $other->maxAge);
     $result->attached = Renderer::mergeAttachments($this->attached, $other->attached);
     $result->postRenderCache = NestedArray::mergeDeep($this->postRenderCache, $other->postRenderCache);
     return $result;
 }
开发者ID:Nikola-xiii,项目名称:d8intranet,代码行数:23,代码来源:BubbleableMetadata.php

示例2: mergeCacheabilityFromConditions

 /**
  * Merges cacheable metadata from conditions onto the access result object.
  *
  * @param \Drupal\Core\Access\AccessResult $access
  *   The access result object.
  * @param \Drupal\Core\Condition\ConditionInterface[] $conditions
  *   List of visibility conditions.
  */
 protected function mergeCacheabilityFromConditions(AccessResult $access, array $conditions)
 {
     foreach ($conditions as $condition) {
         if ($condition instanceof CacheableDependencyInterface) {
             $access->addCacheTags($condition->getCacheTags());
             $access->addCacheContexts($condition->getCacheContexts());
             $access->setCacheMaxAge(Cache::mergeMaxAges($access->getCacheMaxAge(), $condition->getCacheMaxAge()));
         }
     }
 }
开发者ID:aWEBoLabs,项目名称:taxi,代码行数:18,代码来源:BlockAccessControlHandler.php

示例3: applyDisplayCachablityMetadata

 /**
  * Applies the cacheability of the current display to the given render array.
  *
  * @param array $element
  *   The render array with updated cacheability metadata.
  */
 protected function applyDisplayCachablityMetadata(array &$element)
 {
     /** @var \Drupal\views\Plugin\views\cache\CachePluginBase $cache */
     $cache = $this->getPlugin('cache');
     (new CacheableMetadata())->setCacheTags(Cache::mergeTags($this->view->getCacheTags(), isset($this->display['cache_metadata']['tags']) ? $this->display['cache_metadata']['tags'] : []))->setCacheContexts(isset($this->display['cache_metadata']['contexts']) ? $this->display['cache_metadata']['contexts'] : [])->setCacheMaxAge(Cache::mergeMaxAges($cache->getCacheMaxAge(), isset($this->display['cache_metadata']['max-age']) ? $this->display['cache_metadata']['max-age'] : Cache::PERMANENT))->merge(CacheableMetadata::createFromRenderArray($element))->applyTo($element);
 }
开发者ID:318io,项目名称:318-io,代码行数:12,代码来源:DisplayPluginBase.php

示例4: getCacheMaxAge

  /**
   * {@inheritdoc}
   */
  public function getCacheMaxAge() {
    $max_age = parent::getCacheMaxAge();
    foreach ($this->getAllEntities() as $entity) {
      $max_age = Cache::mergeMaxAges($max_age, $entity->getCacheMaxAge());
    }

    return $max_age;
  }
开发者ID:jthoresen,项目名称:PladsenDrupal,代码行数:11,代码来源:Sql.php

示例5: getCacheMaxAge

 /**
  * Gets the max age for the current view.
  *
  * @return int
  */
 public function getCacheMaxAge()
 {
     $max_age = $this->getDefaultCacheMaxAge();
     $max_age = Cache::mergeMaxAges($max_age, $this->view->getQuery()->getCacheMaxAge());
     return $max_age;
 }
开发者ID:jeyram,项目名称:camp-gdl,代码行数:11,代码来源:CachePluginBase.php

示例6: inheritCacheability

 /**
  * Inherits the cacheability of the other access result, if any.
  *
  * inheritCacheability() differs from addCacheableDependency() in how it
  * handles max-age, because it is designed to inherit the cacheability of the
  * second operand in the andIf() and orIf() operations. There, the situation
  * "allowed, max-age=0 OR allowed, max-age=1000" needs to yield max-age 1000
  * as the end result.
  *
  * @param \Drupal\Core\Access\AccessResultInterface $other
  *   The other access result, whose cacheability (if any) to inherit.
  *
  * @return $this
  */
 public function inheritCacheability(AccessResultInterface $other)
 {
     $this->addCacheableDependency($other);
     if ($other instanceof CacheableDependencyInterface) {
         if ($this->getCacheMaxAge() !== 0 && $other->getCacheMaxAge() !== 0) {
             $this->setCacheMaxAge(Cache::mergeMaxAges($this->getCacheMaxAge(), $other->getCacheMaxAge()));
         } else {
             $this->setCacheMaxAge($other->getCacheMaxAge());
         }
     }
     return $this;
 }
开发者ID:318io,项目名称:318-io,代码行数:26,代码来源:AccessResult.php

示例7: getCacheMaxAge

 /**
  * {@inheritdoc}
  */
 public function getCacheMaxAge()
 {
     $max_age = Cache::PERMANENT;
     // Asks all subplugins (argument defaults, argument validator and styles).
     if (($plugin = $this->getPlugin('argument_default')) && $plugin instanceof CacheableDependencyInterface) {
         $max_age = Cache::mergeMaxAges($max_age, $plugin->getCacheMaxAge());
     }
     if (($plugin = $this->getPlugin('argument_validator')) && $plugin instanceof CacheableDependencyInterface) {
         $max_age = Cache::mergeMaxAges($max_age, $plugin->getCacheMaxAge());
     }
     // Summaries use style plugins.
     if (($plugin = $this->getPlugin('style')) && $plugin instanceof CacheableDependencyInterface) {
         $max_age = Cache::mergeMaxAges($max_age, $plugin->getCacheMaxAge());
     }
     return $max_age;
 }
开发者ID:HakS,项目名称:drupal8_training,代码行数:19,代码来源:ArgumentPluginBase.php

示例8: testMergeMaxAges

 /**
  * @covers ::mergeMaxAges
  *
  * @dataProvider mergeMaxAgesProvider
  */
 public function testMergeMaxAges($a, $b, $expected)
 {
     $this->assertSame($expected, Cache::mergeMaxAges($a, $b));
 }
开发者ID:Nikola-xiii,项目名称:d8intranet,代码行数:9,代码来源:CacheTest.php

示例9: render

 /**
  * {@inheritdoc}
  */
 public function render()
 {
     $build = array();
     $build['#markup'] = $this->view->style_plugin->render();
     // Wrap the output in a pre tag if this is for a live preview.
     if (!empty($this->view->live_preview)) {
         $build['#prefix'] = '<pre>';
         $build['#markup'] = SafeMarkup::checkPlain($build['#markup']);
         $build['#suffix'] = '</pre>';
     }
     // Defaults for bubbleable rendering metadata.
     $build['#cache']['tags'] = isset($build['#cache']['tags']) ? $build['#cache']['tags'] : array();
     $build['#cache']['max-age'] = isset($build['#cache']['max-age']) ? $build['#cache']['max-age'] : Cache::PERMANENT;
     /** @var \Drupal\views\Plugin\views\cache\CachePluginBase $cache */
     $cache = $this->getPlugin('cache');
     $build['#cache']['tags'] = Cache::mergeTags($build['#cache']['tags'], $cache->getCacheTags());
     $build['#cache']['max-age'] = Cache::mergeMaxAges($build['#cache']['max-age'], $cache->getCacheMaxAge());
     return $build;
 }
开发者ID:nstielau,项目名称:drops-8,代码行数:22,代码来源:RestExport.php

示例10: build

 /**
  * {@inheritdoc}
  */
 public function build()
 {
     $build = [];
     // Default the max page age to permanent.
     $max_page_age = Cache::PERMANENT;
     $page = $this->executable->getPage();
     // Set default page cache keys that include the page and display.
     $page_cache_keys = ['page_manager_page', $page->id(), $this->configuration['uuid']];
     $page_cache_contexts = [];
     $contexts = $this->getContexts();
     foreach ($this->getRegionAssignments() as $region => $blocks) {
         if (!$blocks) {
             continue;
         }
         $region_name = Html::getClass("block-region-{$region}");
         $build['regions'][$region]['#prefix'] = '<div class="' . $region_name . '">';
         $build['regions'][$region]['#suffix'] = '</div>';
         /** @var $blocks \Drupal\Core\Block\BlockPluginInterface[] */
         $weight = 0;
         foreach ($blocks as $block_id => $block) {
             if ($block instanceof ContextAwarePluginInterface) {
                 $this->contextHandler()->applyContextMapping($block, $contexts);
             }
             if (!$block->access($this->account)) {
                 continue;
             }
             $max_age = $block->getCacheMaxAge();
             $block_build = ['#theme' => 'block', '#attributes' => [], '#weight' => $weight++, '#configuration' => $block->getConfiguration(), '#plugin_id' => $block->getPluginId(), '#base_plugin_id' => $block->getBaseId(), '#derivative_plugin_id' => $block->getDerivativeId(), '#block_plugin' => $block, '#pre_render' => [[$this, 'buildBlock']], '#cache' => ['keys' => ['page_manager_page', $page->id(), 'block', $block_id], 'tags' => Cache::mergeTags($page->getCacheTags(), $block->getCacheTags()), 'contexts' => $block->getCacheContexts(), 'max-age' => $max_age]];
             // Build the cache key and a list of all contexts for the whole page.
             $page_cache_keys[] = $block_id;
             $page_cache_contexts = Cache::mergeContexts($page_cache_contexts, $block_build['#cache']['contexts']);
             if (!empty($block_build['#configuration']['label'])) {
                 $block_build['#configuration']['label'] = SafeMarkup::checkPlain($block_build['#configuration']['label']);
             }
             // Update the page max age, set it to the lowest max age of all blocks.
             $max_page_age = Cache::mergeMaxAges($max_age, $max_page_age);
             $build['regions'][$region][$block_id] = $block_build;
         }
     }
     $build['#title'] = $this->renderPageTitle($this->configuration['page_title']);
     if ($max_page_age !== 0) {
         // If all blocks of this page can be cached, then the max page age is not
         // 0. In this case, we additionally cache the whole page, so we need
         // to fetch fewer caches. Also explicitly provide the cache contexts,
         // additional contexts might still bubble up from the block content, but
         // if not, then we save a cache redirection.
         // We don't have to set those values in case we can't cache all blocks,
         // as they will bubble up from the blocks.
         $build['regions']['#cache'] = ['keys' => $page_cache_keys, 'contexts' => $page_cache_contexts, 'max-age' => $max_page_age];
     }
     return $build;
 }
开发者ID:pulibrary,项目名称:recap,代码行数:55,代码来源:BlockDisplayVariant.php

示例11: getCacheMaxAge

 /**
  * {@inheritdoc}
  */
 public function getCacheMaxAge()
 {
     $max_age = parent::getCacheMaxAge();
     // @todo Configurability of this will be removed in
     //   https://www.drupal.org/node/2458763.
     return Cache::mergeMaxAges($max_age, (int) $this->configuration['cache']['max_age']);
 }
开发者ID:ravindrasingh22,项目名称:Drupal-8-rc,代码行数:10,代码来源:BlockBase.php

示例12: getCacheMaxAge

 /**
  * {@inheritdoc}
  */
 public function getCacheMaxAge()
 {
     $max_age = Cache::PERMANENT;
     // Applied contexts can affect the cache max age when this plugin is
     // involved in caching, collect and return them.
     foreach ($this->getContexts() as $context) {
         /** @var $context \Drupal\Core\Cache\CacheableDependencyInterface */
         if ($context instanceof CacheableDependencyInterface) {
             $max_age = Cache::mergeMaxAges($max_age, $context->getCacheMaxAge());
         }
     }
     return $max_age;
 }
开发者ID:HakS,项目名称:drupal8_training,代码行数:16,代码来源:ContextAwarePluginBase.php

示例13: getCacheMaxAge

  /**
   * {@inheritdoc}
   */
  public function getCacheMaxAge() {
    $cache_max_age = Cache::mergeMaxAges(parent::getCacheMaxAge(), $this->view->storage->getCacheMaxAge());

    return $cache_max_age;
  }
开发者ID:eloiv,项目名称:botafoc.cat,代码行数:8,代码来源:EntityReference.php

示例14: renderResponse

 /**
  * {@inheritdoc}
  *
  * The entire HTML: takes a #type 'page' and wraps it in a #type 'html'.
  */
 public function renderResponse(array $main_content, Request $request, RouteMatchInterface $route_match)
 {
     list($page, $title) = $this->prepare($main_content, $request, $route_match);
     if (!isset($page['#type']) || $page['#type'] !== 'page') {
         throw new \LogicException('Must be #type page');
     }
     $page['#title'] = $title;
     // Now render the rendered page.html.twig template inside the html.html.twig
     // template, and use the bubbled #attached metadata from $page to ensure we
     // load all attached assets.
     $html = ['#type' => 'html', 'page' => $page];
     $html += element_info('html');
     // The special page regions will appear directly in html.html.twig, not in
     // page.html.twig, hence add them here, just before rendering html.html.twig.
     $this->buildPageTopAndBottom($html);
     // The three parts of rendered markup in html.html.twig (page_top, page and
     // page_bottom) must be rendered with drupal_render_root(), so that their
     // #post_render_cache callbacks are executed (which may attach additional
     // assets).
     // html.html.twig must be able to render the final list of attached assets,
     // and hence may not execute any #post_render_cache_callbacks (because they
     // might add yet more assets to be attached), and therefore it must be
     // rendered with drupal_render(), not drupal_render_root().
     $this->renderer->render($html['page'], TRUE);
     if (isset($html['page_top'])) {
         $this->renderer->render($html['page_top'], TRUE);
     }
     if (isset($html['page_bottom'])) {
         $this->renderer->render($html['page_bottom'], TRUE);
     }
     $content = $this->renderer->render($html);
     // Expose the cache contexts and cache tags associated with this page in a
     // X-Drupal-Cache-Contexts and X-Drupal-Cache-Tags header respectively. Also
     // associate the "rendered" cache tag. This allows us to invalidate the
     // entire render cache, regardless of the cache bin.
     $cache_contexts = [];
     $cache_tags = ['rendered'];
     $cache_max_age = Cache::PERMANENT;
     foreach (['page_top', 'page', 'page_bottom'] as $region) {
         if (isset($html[$region])) {
             $cache_contexts = Cache::mergeContexts($cache_contexts, $html[$region]['#cache']['contexts']);
             $cache_tags = Cache::mergeTags($cache_tags, $html[$region]['#cache']['tags']);
             $cache_max_age = Cache::mergeMaxAges($cache_max_age, $html[$region]['#cache']['max-age']);
         }
     }
     // Set the generator in the HTTP header.
     list($version) = explode('.', \Drupal::VERSION, 2);
     $response = new Response($content, 200, ['X-Drupal-Cache-Tags' => implode(' ', $cache_tags), 'X-Drupal-Cache-Contexts' => implode(' ', $this->cacheContexts->optimizeTokens($cache_contexts)), 'X-Generator' => 'Drupal ' . $version . ' (https://www.drupal.org)']);
     // If an explicit non-infinite max-age is specified by a part of the page,
     // respect that by applying it to the response's headers.
     if ($cache_max_age !== Cache::PERMANENT) {
         $response->setMaxAge($cache_max_age);
     }
     return $response;
 }
开发者ID:Nikola-xiii,项目名称:d8intranet,代码行数:60,代码来源:HtmlRenderer.php

示例15: inheritCacheability

 /**
  * Inherits the cacheability of the other access result, if any.
  *
  * @param \Drupal\Core\Access\AccessResultInterface $other
  *   The other access result, whose cacheability (if any) to inherit.
  *
  * @return $this
  */
 public function inheritCacheability(AccessResultInterface $other)
 {
     if ($other instanceof CacheableInterface) {
         $this->setCacheable($other->isCacheable());
         $this->addCacheContexts($other->getCacheContexts());
         $this->addCacheTags($other->getCacheTags());
         $this->setCacheMaxAge(Cache::mergeMaxAges($this->getCacheMaxAge(), $other->getCacheMaxAge()));
     } else {
         $this->setCacheable(FALSE);
     }
     return $this;
 }
开发者ID:Nikola-xiii,项目名称:d8intranet,代码行数:20,代码来源:AccessResult.php


注:本文中的Drupal\Core\Cache\Cache::mergeMaxAges方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。