Issue #2562757 by Wim Leers: Various small cacheability fixes that are blocking SmartCache
parent
e3d5340a1b
commit
ae7ec6c585
|
@ -52,6 +52,11 @@ class ConfirmFormHelper {
|
|||
'#title' => $form->getCancelText(),
|
||||
'#attributes' => ['class' => ['button']],
|
||||
'#url' => $url,
|
||||
'#cache' => [
|
||||
'contexts' => [
|
||||
'url.query_args:destination',
|
||||
],
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
|
|
|
@ -16,6 +16,9 @@ use Symfony\Component\HttpFoundation\RequestStack;
|
|||
|
||||
/**
|
||||
* Wraps the caching logic for the render caching system.
|
||||
*
|
||||
* @todo Refactor this out into a generic service capable of cache redirects,
|
||||
* and let RenderCache use that. https://www.drupal.org/node/2551419
|
||||
*/
|
||||
class RenderCache implements RenderCacheInterface {
|
||||
|
||||
|
|
|
@ -63,7 +63,7 @@ class TestAccessBlock extends BlockBase implements ContainerFactoryPluginInterfa
|
|||
* {@inheritdoc}
|
||||
*/
|
||||
protected function blockAccess(AccountInterface $account) {
|
||||
return $this->state->get('test_block_access', FALSE) ? AccessResult::allowed() : AccessResult::forbidden();
|
||||
return $this->state->get('test_block_access', FALSE) ? AccessResult::allowed()->setCacheMaxAge(0) : AccessResult::forbidden()->setCacheMaxAge(0);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
namespace Drupal\book\Tests;
|
||||
|
||||
use Drupal\Component\Utility\SafeMarkup;
|
||||
use Drupal\Core\Cache\Cache;
|
||||
use Drupal\Core\Entity\EntityInterface;
|
||||
use Drupal\simpletest\WebTestBase;
|
||||
use Drupal\user\RoleInterface;
|
||||
|
@ -124,11 +125,12 @@ class BookTest extends WebTestBase {
|
|||
|
||||
// Enable the debug output.
|
||||
\Drupal::state()->set('book_test.debug_book_navigation_cache_context', TRUE);
|
||||
Cache::invalidateTags(['book_test.debug_book_navigation_cache_context']);
|
||||
|
||||
$this->drupalLogin($this->bookAuthor);
|
||||
|
||||
// On non-node route.
|
||||
$this->drupalGet('');
|
||||
$this->drupalGet($this->adminUser->urlInfo());
|
||||
$this->assertRaw('[route.book_navigation]=book.none');
|
||||
|
||||
// On non-book node route.
|
||||
|
|
|
@ -15,6 +15,7 @@
|
|||
* Implements hook_page_attachments().
|
||||
*/
|
||||
function book_test_page_attachments(array &$page) {
|
||||
$page['#cache']['tags'][] = 'book_test.debug_book_navigation_cache_context';
|
||||
if (\Drupal::state()->get('book_test.debug_book_navigation_cache_context', FALSE)) {
|
||||
drupal_set_message(\Drupal::service('cache_contexts_manager')->convertTokensToKeys(['route.book_navigation'])->getKeys()[0]);
|
||||
}
|
||||
|
|
|
@ -399,7 +399,7 @@ class PageCacheTest extends WebTestBase {
|
|||
// that implementation.
|
||||
\Drupal::state()->set('page_cache_bypass_form_immutability', TRUE);
|
||||
\Drupal::moduleHandler()->resetImplementations();
|
||||
\Drupal::cache('render')->deleteAll();
|
||||
Cache::invalidateTags(['rendered']);
|
||||
|
||||
$this->drupalGet('page_cache_form_test_immutability');
|
||||
|
||||
|
|
|
@ -7,6 +7,8 @@
|
|||
|
||||
namespace Drupal\path\Tests;
|
||||
|
||||
use Drupal\Core\Cache\Cache;
|
||||
|
||||
/**
|
||||
* Add, edit, delete, and change alias and verify its consistency in the
|
||||
* database.
|
||||
|
@ -57,6 +59,8 @@ class PathAliasTest extends PathTestBase {
|
|||
|
||||
// Visit the alias for the node and confirm a cache entry is created.
|
||||
\Drupal::cache('data')->deleteAll();
|
||||
// @todo Remove this once https://www.drupal.org/node/2480077 lands.
|
||||
Cache::invalidateTags(['rendered']);
|
||||
$this->drupalGet(trim($edit['alias'], '/'));
|
||||
$this->assertTrue(\Drupal::cache('data')->get('preload-paths:' . $edit['source']), 'Cache entry was created.');
|
||||
}
|
||||
|
|
|
@ -75,6 +75,7 @@ class SearchController extends ControllerBase {
|
|||
|
||||
// Build the form first, because it may redirect during the submit,
|
||||
// and we don't want to build the results based on last time's request.
|
||||
$build['#cache']['contexts'][] = 'url.query_args:keys';
|
||||
if ($request->query->has('keys')) {
|
||||
$keys = trim($request->get('keys'));
|
||||
$plugin->setSearch($keys, $request->query->all(), $request->attributes->all());
|
||||
|
|
|
@ -60,8 +60,8 @@ class ConfigCacheTag implements EventSubscriberInterface {
|
|||
$this->cacheTagsInvalidator->invalidateTags(['route_match', 'rendered']);
|
||||
}
|
||||
|
||||
// Global theme settings.
|
||||
if ($event->getConfig()->getName() === 'system.theme.global') {
|
||||
// Theme configuration and global theme settings.
|
||||
if (in_array($event->getConfig()->getName(), ['system.theme', 'system.theme.global'])) {
|
||||
$this->cacheTagsInvalidator->invalidateTags(['rendered']);
|
||||
}
|
||||
|
||||
|
|
|
@ -40,6 +40,11 @@ class BatchTestMultiStepForm extends FormBase {
|
|||
'#value' => 'Submit',
|
||||
);
|
||||
|
||||
// This is a POST form with multiple steps that does not transition from one
|
||||
// step to the next via POST requests, but via GET requests, because it uses
|
||||
// Batch API to advance through the steps.
|
||||
$form['#cache']['max-age'] = 0;
|
||||
|
||||
return $form;
|
||||
}
|
||||
|
||||
|
|
|
@ -25,6 +25,8 @@ class TestControllers {
|
|||
}
|
||||
|
||||
public function testEntityLanguage(NodeInterface $node) {
|
||||
return ['#markup' => $node->label()];
|
||||
$build = ['#markup' => $node->label()];
|
||||
\Drupal::service('renderer')->addCacheableDependency($build, $node);
|
||||
return $build;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -33,6 +33,7 @@ class ConfirmFormHelperTest extends UnitTestCase {
|
|||
|
||||
$link = ConfirmFormHelper::buildCancelLink($form, new Request());
|
||||
$this->assertSame($cancel_text, $link['#title']);
|
||||
$this->assertSame(['contexts' => ['url.query_args:destination']], $link['#cache']);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -49,6 +50,7 @@ class ConfirmFormHelperTest extends UnitTestCase {
|
|||
->will($this->returnValue($cancel_route));
|
||||
$link = ConfirmFormHelper::buildCancelLink($form, new Request());
|
||||
$this->assertEquals(Url::fromRoute($route_name), $link['#url']);
|
||||
$this->assertSame(['contexts' => ['url.query_args:destination']], $link['#cache']);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -64,6 +66,7 @@ class ConfirmFormHelperTest extends UnitTestCase {
|
|||
->will($this->returnValue($expected));
|
||||
$link = ConfirmFormHelper::buildCancelLink($form, new Request());
|
||||
$this->assertEquals($expected, $link['#url']);
|
||||
$this->assertSame(['contexts' => ['url.query_args:destination']], $link['#cache']);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -86,6 +89,7 @@ class ConfirmFormHelperTest extends UnitTestCase {
|
|||
->will($this->returnValue($cancel_route));
|
||||
$link = ConfirmFormHelper::buildCancelLink($form, new Request());
|
||||
$this->assertSame($cancel_route, $link['#url']);
|
||||
$this->assertSame(['contexts' => ['url.query_args:destination']], $link['#cache']);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -112,6 +116,7 @@ class ConfirmFormHelperTest extends UnitTestCase {
|
|||
|
||||
$link = ConfirmFormHelper::buildCancelLink($form, new Request($query));
|
||||
$this->assertSame($url, $link['#url']);
|
||||
$this->assertSame(['contexts' => ['url.query_args:destination']], $link['#cache']);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue