Commit a05ca5d2 authored by catch's avatar catch
Browse files

Issue #2653346 by Wim Leers, borisson_: Add UncacheableDependencyTrait: the...

Issue #2653346 by Wim Leers, borisson_: Add UncacheableDependencyTrait: the opposite of UnchangingCacheableDependencyTrait
parent e60bb570
Loading
Loading
Loading
Loading
+40 −0
Changes for core/lib/Drupal/Core/Cache/UncacheableDependencyTrait.php: 40 added lines, 0 removed lines.
Original line number Diff line number Diff line
<?php

/**
 * @file
 * Contains \Drupal\Core\Cache\UncacheableDependencyTrait.
 */

namespace Drupal\Core\Cache;

/**
 * Trait to implement CacheableDependencyInterface for uncacheable objects.
 *
 * Use this for objects that are never cacheable.
 *
 * @see \Drupal\Core\Cache\CacheableDependencyInterface
 */
trait UncacheableDependencyTrait {

  /**
   * {@inheritdoc}
   */
  public function getCacheContexts() {
    return [];
  }

  /**
   * {@inheritdoc}
   */
  public function getCacheTags() {
    return [];
  }

  /**
   * {@inheritdoc}
   */
  public function getCacheMaxAge() {
    return 0;
  }

}
+3 −8
Changes for core/modules/history/src/Plugin/views/filter/HistoryUserTimestamp.php: 3 added lines, 8 removed lines.
Original line number Diff line number Diff line
@@ -2,6 +2,7 @@

namespace Drupal\history\Plugin\views\filter;

use Drupal\Core\Cache\UncacheableDependencyTrait;
use Drupal\Core\Form\FormStateInterface;
use Drupal\views\Plugin\views\filter\FilterPluginBase;

@@ -17,6 +18,8 @@
 */
class HistoryUserTimestamp extends FilterPluginBase {

  use UncacheableDependencyTrait;

  // Don't display empty space where the operator would be.
  var $no_operator = TRUE;

@@ -93,12 +96,4 @@ public function adminSummary() {
    }
  }

  /**
   * {@inheritdoc}
   */
  public function getCacheMaxAge() {
    // This filter depends on the current time and therefore is never cacheable.
    return 0;
  }

}
+2 −20
Changes for core/modules/system/tests/modules/early_rendering_controller_test/src/CacheableTestDomainObject.php: 2 added lines, 20 removed lines.
Original line number Diff line number Diff line
@@ -3,28 +3,10 @@
namespace Drupal\early_rendering_controller_test;

use Drupal\Core\Cache\CacheableDependencyInterface;
use Drupal\Core\Cache\UncacheableDependencyTrait;

class CacheableTestDomainObject extends TestDomainObject implements CacheableDependencyInterface {

  /**
   * {@inheritdoc}
   */
  public function getCacheContexts() {
    return [];
  }

  /**
   * {@inheritdoc}
   */
  public function getCacheTags() {
    return [];
  }

  /**
   * {@inheritdoc}
   */
  public function getCacheMaxAge() {
    return 0;
  }
  use UncacheableDependencyTrait;

}
+3 −21
Changes for core/modules/views/src/Plugin/views/sort/Random.php: 3 added lines, 21 removed lines.
Original line number Diff line number Diff line
@@ -3,6 +3,7 @@
namespace Drupal\views\Plugin\views\sort;

use Drupal\Core\Cache\CacheableDependencyInterface;
use Drupal\Core\Cache\UncacheableDependencyTrait;
use Drupal\Core\Form\FormStateInterface;

/**
@@ -12,6 +13,8 @@
 */
class Random extends SortPluginBase implements CacheableDependencyInterface {

  use UncacheableDependencyTrait;

  /**
   * {@inheritdoc}
   */
@@ -28,25 +31,4 @@ public function buildOptionsForm(&$form, FormStateInterface $form_state) {
    $form['order']['#access'] = FALSE;
  }

  /**
   * {@inheritdoc}
   */
  public function getCacheMaxAge() {
    return 0;
  }

  /**
   * {@inheritdoc}
   */
  public function getCacheContexts() {
    return [];
  }

  /**
   * {@inheritdoc}
   */
  public function getCacheTags() {
    return [];
  }

}