Problem/Motivation

See #2994348: Prefetch Cache contrib module + BigPipe: prefetching for more information.

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

CommentFileSizeAuthor
#4 2994355-4.patch3.89 KBhchonov
#2 2994355-2.patch447 byteshchonov

Comments

hchonov created an issue. See original summary.

hchonov’s picture

Status: Active » Needs review
StatusFileSize
new447 bytes

Status: Needs review » Needs work

The last submitted patch, 2: 2994355-2.patch, failed testing. View results

hchonov’s picture

Status: Needs work » Needs review
StatusFileSize
new3.89 KB

After the discussion on #2994348: Prefetch Cache contrib module + BigPipe: prefetching and as suggested by @Wim Leers, we will disable BigPipe by decorating the BigPipe Placeholder Strategy service.

hchonov credited Wim Leers.

hchonov’s picture

Giving credit to @Wim Leers for the suggested approach.

Status: Needs review » Needs work

The last submitted patch, 4: 2994355-4.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

wim leers’s picture

LGTM!

Just one remark:

  1. +++ b/src/Render/Placeholder/PrefetchCacheStrategy.php
    @@ -0,0 +1,53 @@
    +    // Prefetch Cache requests should not be processed by Big Pipe, as the
    

    Nit: s/Big Pipe/BigPipe/

  2. +++ b/src/Render/Placeholder/PrefetchCacheStrategy.php
    @@ -0,0 +1,53 @@
    +    $prefetch_cache_request = $this->requestStack->getCurrentRequest()->attributes->has(PrefetchCacheInterface::PREFETCH_CACHE_REQUEST);
    

    This means responses now vary by

    'url.query_args:' .
     PrefetchCacheInterface::PREFETCH_CACHE_REQUEST

    .

    So you need to add that cache context to relevant HTML responses. BigPipe does something similar in big_pipe_page_attachments(). You'll also want to implement hook_page_attachments() and add that particular cache context.

    Ideally you'd have a simple functional test that accesses the frontpage with and without your URL query arg, and observe BigPipe to be loaded versus not.

hchonov’s picture

+++ b/src/Render/Placeholder/PrefetchCacheStrategy.php
@@ -0,0 +1,53 @@
+    $prefetch_cache_request = $this->requestStack->getCurrentRequest()->attributes->has(PrefetchCacheInterface::PREFETCH_CACHE_REQUEST);

This means responses now vary by

'url.query_args:' .
 PrefetchCacheInterface::PREFETCH_CACHE_REQUEST

Actually they don't :). If you take a look again at the code, then you'll see that at that place I check for the existence of a request attribute and not a request query parameter. The query parameter is removed from the request early in the chain in

\Drupal\prefetch_cache\StackMiddleware\PrefetchCacheBeforePageCache::handle()

and the query parameter cache context isn't being added deliberately. A prefetch cache request should simulate (behave just like) a regular request and maximize the cache hits.

  • hchonov committed 07a27e8 on 8.x-1.x
    Issue #2994355 by hchonov, Wim Leers: Prefetch cache doesn't work when...
wim leers’s picture

Status: Needs work » Fixed

Ah, right, good point! And clever :)

wim leers’s picture

hchonov’s picture

Ah, right, good point! And clever :)

Thank you :).

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.