summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNathaniel Catchpole2016-04-11 11:15:33 +0900
committerNathaniel Catchpole2016-04-11 11:15:33 +0900
commita05ca5d26e0d025fae828ce4e70a8f728f120650 (patch)
treeb424788ded40f0c93aa659130840e22d538e914a
parente60bb5703e12909b8eaa2b68b010211131550d7f (diff)
Issue #2653346 by Wim Leers, borisson_: Add UncacheableDependencyTrait: the opposite of UnchangingCacheableDependencyTrait
-rw-r--r--core/lib/Drupal/Core/Cache/UncacheableDependencyTrait.php40
-rw-r--r--core/modules/history/src/Plugin/views/filter/HistoryUserTimestamp.php11
-rw-r--r--core/modules/system/tests/modules/early_rendering_controller_test/src/CacheableTestDomainObject.php22
-rw-r--r--core/modules/views/src/Plugin/views/sort/Random.php24
4 files changed, 48 insertions, 49 deletions
diff --git a/core/lib/Drupal/Core/Cache/UncacheableDependencyTrait.php b/core/lib/Drupal/Core/Cache/UncacheableDependencyTrait.php
new file mode 100644
index 0000000..a2f00e8
--- /dev/null
+++ b/core/lib/Drupal/Core/Cache/UncacheableDependencyTrait.php
@@ -0,0 +1,40 @@
+<?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;
+ }
+
+}
diff --git a/core/modules/history/src/Plugin/views/filter/HistoryUserTimestamp.php b/core/modules/history/src/Plugin/views/filter/HistoryUserTimestamp.php
index 92e1acd..5803c92 100644
--- a/core/modules/history/src/Plugin/views/filter/HistoryUserTimestamp.php
+++ b/core/modules/history/src/Plugin/views/filter/HistoryUserTimestamp.php
@@ -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 @@ use Drupal\views\Plugin\views\filter\FilterPluginBase;
*/
class HistoryUserTimestamp extends FilterPluginBase {
+ use UncacheableDependencyTrait;
+
// Don't display empty space where the operator would be.
var $no_operator = TRUE;
@@ -93,12 +96,4 @@ class HistoryUserTimestamp extends FilterPluginBase {
}
}
- /**
- * {@inheritdoc}
- */
- public function getCacheMaxAge() {
- // This filter depends on the current time and therefore is never cacheable.
- return 0;
- }
-
}
diff --git a/core/modules/system/tests/modules/early_rendering_controller_test/src/CacheableTestDomainObject.php b/core/modules/system/tests/modules/early_rendering_controller_test/src/CacheableTestDomainObject.php
index 843d785..9da6fd8 100644
--- a/core/modules/system/tests/modules/early_rendering_controller_test/src/CacheableTestDomainObject.php
+++ b/core/modules/system/tests/modules/early_rendering_controller_test/src/CacheableTestDomainObject.php
@@ -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;
}
diff --git a/core/modules/views/src/Plugin/views/sort/Random.php b/core/modules/views/src/Plugin/views/sort/Random.php
index 11e216b..c9a552f 100644
--- a/core/modules/views/src/Plugin/views/sort/Random.php
+++ b/core/modules/views/src/Plugin/views/sort/Random.php
@@ -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 @@ use Drupal\Core\Form\FormStateInterface;
*/
class Random extends SortPluginBase implements CacheableDependencyInterface {
+ use UncacheableDependencyTrait;
+
/**
* {@inheritdoc}
*/
@@ -28,25 +31,4 @@ class Random extends SortPluginBase implements CacheableDependencyInterface {
$form['order']['#access'] = FALSE;
}
- /**
- * {@inheritdoc}
- */
- public function getCacheMaxAge() {
- return 0;
- }
-
- /**
- * {@inheritdoc}
- */
- public function getCacheContexts() {
- return [];
- }
-
- /**
- * {@inheritdoc}
- */
- public function getCacheTags() {
- return [];
- }
-
}