Quantcast
Channel: Issues for Drupal core
Viewing all articles
Browse latest Browse all 300674

Varnish issue with dynamic page cache module

$
0
0

Updated content not reflecting on front end for anonymous user if page have "X-drupal-dynamic-cache" header is set as "UNCACHEABLE"

1. Install dynamic page cache.
2. Set up varnish.
3. Pass "User" cache context to that page through custom code.
4. Now you will see "X-drupal-dynamic-cache" header as "UNCACHEABLE"
5. However, this page will be cached to varnish
6. Now try to update the content then cache for that page does not purge from varnish. So updated content will not reflect on frontend for anonymous until we clear the varnish cache directly from varnish.

If we have user or session cache context on a page then dynamic page cache module set "X-drupal-dynamic-cache" header as "UNCACHEABLE" due to which purge module does not able to set "X-Acquia-Site" header for that page.

If page does not have "X-Acquia-Site" header set then Varnish is not able to purge cache for that page on tag invalidation.

So can we create a patch for Dynamic Cache Module so that it will never set "X-drupal-dynamic-cache" header as "UNCACHEABLE" for anonymous user?

diff --git a/core/modules/dynamic_page_cache/src/EventSubscriber/DynamicPageCacheSubscriber.php b/core/modules/dynamic_page_cache/src/EventSubscriber/DynamicPageCacheSubscriber.php
index 22b51b9e..4e961b44 100644
--- a/core/modules/dynamic_page_cache/src/EventSubscriber/DynamicPageCacheSubscriber.php
+++ b/core/modules/dynamic_page_cache/src/EventSubscriber/DynamicPageCacheSubscriber.php
@@ -165,7 +165,8 @@ class DynamicPageCacheSubscriber implements EventSubscriberInterface {
     }
 
     // There's no work left to be done if this is an uncacheable response.
-    if (!$this->shouldCacheResponse($response)) {
+    // Do not set uncacheable for anonymous user.
+    if (!\Drupal::currentUser()->isAnonymous() && !$this->shouldCacheResponse($response)) {
       // The response is uncacheable, mark it as such.
       $response->headers->set(self::HEADER, 'UNCACHEABLE');
       return;

Viewing all articles
Browse latest Browse all 300674

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>