Question about sample page "cached-max-age"

Created on 2 May 2024, 8 months ago
Updated 2 June 2024, 7 months ago

Oleg,

I don't quite understand the behavior I'm seeing on /cache-review/cached-max-age, specifically regarding "block" 04. As a non-admin authenticated user, if I add a query string to the URL (something like ?test=1), I see that all four blocks get update (by watching their timestamps). Then, if I change the query string to ?test=2 within 20 seconds, I see that only blocks 01, 02, and 04 have updated timestamps. I do not understand why block 03 doesn't. Does it have something to do with the cache key for block 03?

While I'm at it, I must admit that I initially thought that all "blocks" on the sample pages were Drupal blocks, but after looking at the code, I see that most of them are just non-Drupal block render arrays. Might I suggest renaming them to something other than "block" to avoid the confusion?

thanks,
-mike

💬 Support request
Status

Needs review

Version

1.1

Component

Documentation

Created by

🇺🇸United States ultimike Florida, USA

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @ultimike
  • 🇺🇦Ukraine osab Germany, Baden-Württemberg; Ukraine, Kharkiv

    Hello Michael! Thank you for the question. I will try to answer based on my understanding. Please do not consider my answer to be absolute truth )).

    So yes, I see such behavior for admin user also. Here the "keys":["demo_child"] plays role.
    - On the page we have setting "contexts":["url.query_args"] (block 04). That means to invalidate cache if URL query arguments changed, what happened after adding ?test=1.
    - We have "max-age":20 also. So, 20 sec the page is unchangable (block 02).
    - But we also have "max-age":40,"keys":["demo_child"] (block 03). And this block from 21 to av. 40 second will stay freezed (cached) because of "keys". The "keys" is like specific mark means "do not touch this part during invalidation because of some "heavy" calculation here or smth". And then, after 40 sec the "max-age" comes into force and block 03 updates.

    To make sure, that's all works in this way, try to change parameters. For example if you remove "max-age":40 for block 03, after 20 sec all others will get new times, but block 03 become cached.
    At the same time, if remove "keys":["demo_child"], the block 03 will be changed after 20 sec along with others.

    More info I saw here https://bluetext.com/blog/drupal-8-render-caching/,
    https://api.drupal.org/api/drupal/core%21lib%21Drupal%21Core%21Render%21....

    As for "block" naming, yes you're right. That is not good choice. Initially, I've added plugin blocks for lazy-builder and then called other parts as "blocks" also. I don't know, maybe "sections" wil be better? What would you advise?

  • Status changed to Needs review 8 months ago
  • 🇺🇦Ukraine osab Germany, Baden-Württemberg; Ukraine, Kharkiv
  • 🇺🇸United States ultimike Florida, USA

    @osab - Thanks for your response. The fact that a custom cache key causes the render array to be cached independently of the rest of the page is helpful and explains what I'm seeing on /cache-review/cached-max-age

    As for the naming, I think that in the Cache Review sample pages, using the word "section" is much better than using "blocks", IMHO.

    -mike

  • 🇺🇦Ukraine osab Germany, Baden-Württemberg; Ukraine, Kharkiv

    Hi!
    I've updated naming in https://www.drupal.org/project/cache_review/issues/3446118 📌 Add basic test and setup CI Needs work . Only couple blocks and all others are sections there.

Production build 0.71.5 2024