Score:2

Need help understanding caching issue on Pantheon and Redis

ng flag

On a Drupal 9.5 site on Pantehon that uses Redis, we have Drupal cache and the BigPipe module enabled.

The problem is that the cache is only being "hit" (?) if the same user visits a page twice and it's only cached for that user. So, no matter what, each page is always served fresh for a user when they visit each page. This happens on all the pages and testing only for anonymous users.

The HTTP headers output from the first visit are the following.

HTTP/2 200
cache-control: max-age=86400, public
content-language: en
content-type: text/html; charset=UTF-8
etag: W/"1693518926"
expires: Sun, 19 Nov 1978 05:00:00 GMT
last-modified: Thu, 31 Aug 2023 21:55:26 GMT
server: nginx
strict-transport-security: max-age=300
x-content-type-options: nosniff
x-drupal-cache: MISS
x-drupal-dynamic-cache: MISS
x-frame-options: SAMEORIGIN
x-generator: Drupal 9 (https://www.drupal.org)
x-pantheon-styx-hostname: styx-fe1-b-86557c6757-8fm4j
x-styx-req-id: 179f8f79-4849-11ee-8cc1-fad9a4d1262e
x-ua-compatible: IE=edge
date: Thu, 31 Aug 2023 21:55:28 GMT
x-served-by: cache-chi-klot8100114-CHI, cache-dfw-kdfw8210075-DFW
x-cache: MISS, MISS
x-cache-hits: 0, 0
x-timer: S1693518926.101391,VS0,VE2382
vary: Accept-Encoding, Cookie, Cookie, Cookie
age: 0
accept-ranges: bytes
via: 1.1 varnish, 1.1 varnish
content-length: 171901

The HTTP headers output from the second visit are the following.

HTTP/2 200
cache-control: max-age=86400, public
content-language: en
content-type: text/html; charset=UTF-8
etag: W/"1693512342"
expires: Sun, 19 Nov 1978 05:00:00 GMT
last-modified: Thu, 31 Aug 2023 20:05:42 GMT
server: nginx
strict-transport-security: max-age=300
x-content-type-options: nosniff
x-drupal-cache: MISS
x-drupal-dynamic-cache: MISS
x-frame-options: SAMEORIGIN
x-generator: Drupal 9 (https://www.drupal.org)
x-pantheon-styx-hostname: styx-fe1-a-654979455f-8bhkd
x-styx-req-id: c37e6b58-4839-11ee-a70b-82e299cb3735
x-ua-compatible: IE=edge
date: Thu, 31 Aug 2023 21:01:34 GMT
x-served-by: cache-chi-klot8100070-CHI, cache-dfw-kdfw8210108-DFW
x-cache: HIT, MISS
x-cache-hits: 1, 0
x-timer: S1693515695.925941,VS0,VE26
vary: Accept-Encoding, Cookie, Cookie, Cookie
age: 3351
accept-ranges: bytes
via: 1.1 varnish, 1.1 varnish
content-length: 151019

cn flag
There are a few things there that maybe look out of place - the expiry being in the past; the `last-modified` being earlier for the second request; the differing content length; the large difference in `age`. Almost like the server didn't find the cache entry first time round, but managed to find an older version of it second time. Or that could all be fine and not related to the problem (cache headers are misleading sometimes), or if it's wrong it could be down to varnish or nginx config, or your site configuration. It's really hard to say without access to the whole stack
cn flag
Or if 4uk4's insight in your [other question](https://drupal.stackexchange.com/questions/316865/why-does-redis-show-the-top-most-invalidated-tags-as-all-config-system-menu) is right, and something is potentially clearing the cache on every request, you could well end up in this situation. You get a cache hit immediately after the first request, then the tag purger kicks in in the background and clears that cache, so by the next request it's gone
quantumized avatar
ng flag
Thank you for the tips. I'm still troubleshooting and gathering data so this helps. I'll post back if I find the cause.
Greg W avatar
ai flag
@Clive the expiry in the past is set to the Drupal creator’s DOB. Proper caches are supposed to ignore it if a cache-control: max-age header exists (though there are CDNs that ignore the RFC and therefore cannot cache any Drupal page).
4uk4 avatar
cn flag
What's the difference between user1 and user2? Even if you don't log in to Drupal the requests don't seem to be 100% anonymous. Otherwise, Varnish would send the same cached response every time.
cn flag
@GregW I guessed that might be the case (hence “misleading sometimes”), but I didn’t know that was Dries’s birthday, fun fact :)
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.