Review main Merged

90125[BUGFIX] Consider content object cache lifetimes in HTTP cache headers

Benni Mack CR +2 V +2 Normal +53 −15 updated 08/18/25, 12:55

Commit message

The page cache timeout calculation did not consider content-specific
cache lifetimes when no cache tag is given.

This caused situations where content objects with shorter cache
lifetimes (e.g. lib.content.cache.lifetime = 3600) would not affect
the HTTP max-age header, leading to incorrect client-side caching.

When no cache tags are defined, we now restrict the maximum lifetime
to the corresponding cache tag lifetime. Due to differences in how
cache backends handle lifetimes, we cannot alter the existing
calculation logic. instead, a new calculation method for cache
tag lifetimes has been introduced.

Additionally, this change fixes an unrelated issue by ensuring
that the "default" cache lifetime value is handled correctly.

Review

  • Code review CR +2 Done
    • Christian Kuhn +2
    • Stefan Bürk +1
    • Jörg Bösche +1
    • Sascha Nowak +1
  • Verified V +2 Done
    • Christian Kuhn +2
    • Stefan Bürk +1
    • Sascha Nowak +1
    • core-ci +1 CI

Issues 1

Files 3

Review log 3341

Show 1416 earlier messages
  1. Benni Mack uploaded patch set 1 07/22/25, 21:26

  2. core-ci voted on patch set 1 V +1 07/22/25, 21:33 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/82144

  3. Markus Klein voted on patch set 1 CR +1 07/23/25, 09:14

  4. Simon Schaufelberger voted on patch set 1 CR +1 V +1 07/23/25, 14:19

  5. Markus Klein voted on patch set 1 V +1 07/23/25, 14:23

  6. Oli Bartsch voted on patch set 1 CR +1 V +1 07/24/25, 09:03

  7. Benjamin Franzke commented on patch set 1 CR -1 07/25/25, 11:09

    I would like to check this, the idea of Sascha cache collector was that all cache-influencing components are taken into account in `resolveLifetime()` by taking the minium cache lifetime of all cache tags from pages and content elments. With this change the minimium is effectively taken twice: ``` min(min(ContentLifeTime, PageLifeTime), ContentLifeTime) # instead of min(PageLifeTime, ContentLifeTime) ``` I'll check this, also cc @typo3@saschanowak.me as the author of the cache data collector.
  8. Sascha Nowak commented on patch set 1 07/25/25, 11:52

    Reply

    Thanks for tagging me. The idea was, when you add a CacheTag with a lifetime, which is done in the ContentObjectRenderer, then the shortest lifetime of all CacheTags should be used for the page cache entry and the cache control header. The function restrictMaximumLifetime is only there that we can implement features like "clearCacheOnMidnight". @benni@typo3.org when I understand the szenario correctly then you have a page with a long lifetime (24h) and a content element with a short lifetime (1h) and the content element has no access restrictions like start- and enddate. The bug is that the cache control max-age header is 24h and not 1h? I we have one or two more days for review I will try to reproduce the bug and test your change?
  9. Benjamin Franzke commented on patch set 1 07/25/25, 12:18

    Reply

    FYI: Benni provided me with the following reproduction example (didn't verify myself yet): https://forge.typo3.org/issues/83045#note-3 I'd appreciate if you could verifiy this and we definitely have the time to wait 😊 Thanks in advance!
  10. Sascha Nowak commented on patch set 1 07/25/25, 16:52

    ContentObjectRenderer.php:696

    I've identified the root cause of the issue. The current implementation doesn't associate a cache tag or a corresponding lifetime with the generated data. In the specific case referenced in the ticket, no cache tag is assigned at all—meaning the calculated lifetime isn't persisted or reused. A robust solution would be to always attach the cache key as a tag (hashed to a short MD5) and associate the intended lifetime directly with that tag. Once that's in place, the CacheDataCollector handles the rest correctly and consistently. Below is the code that resolves the issue based on the scenario described in the ticket: ``` $tags = [ substr(md5($key), 0, 10), ...$this->calculateCacheTags($cacheConfiguration) ]; $lifetime = $this->calculateCacheLifetime($cacheConfiguration); $cachedData = [ 'content' => $content, 'cacheTags' => $tags, ]; $cacheFrontend->set($key, $cachedData, $tags, $lifetime); $this->getRequest()->getAttribute('frontend.cache.collector')->addCacheTags( ...array_map(fn(string $tag) => new CacheTag($tag, $lifetime ?? PHP_INT_MAX), $tags) ); ``` we can do the same on the other part below. what do you think about the solution @benni@typo3.org?
  11. Benni Mack commented on patch set 1 07/31/25, 16:42

    ContentObjectRenderer.php:696 Reply

    sounds like good to me
  12. Sascha Nowak uploaded patch set 2 CR +1 V +1 08/15/25, 05:19

  13. Sascha Nowak uploaded patch set 3 08/15/25, 05:24

  14. Sascha Nowak uploaded patch set 4 08/15/25, 05:24

  15. Sascha Nowak voted on patch set 4 CR +1 V +1 08/15/25, 05:27

  16. core-ci voted on patch set 2 V -1 08/15/25, 05:27 Copied votes on follow-up patch sets have been updated: * Verified-1 has been copied to patch set 3 (copy condition: "changekind:NO_CHANGE"). Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/83433

  1. Sascha Nowak commented on patch set 4 08/15/25, 05:27

    Reply

    Done

    ContentObjectRenderer.php:696 Reply

    Done
  2. Sascha Nowak uploaded patch set 5 CR +1 V +1 08/15/25, 05:29

  3. Sascha Nowak voted on patch set 5 CR +1 V +1 08/15/25, 05:30

  4. core-ci voted on patch set 3 V -1 08/15/25, 05:34 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/83434

  5. core-ci voted on patch set 4 V -1 08/15/25, 05:35 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/83435

  6. core-ci voted on patch set 5 V -1 08/15/25, 05:37 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/83436

  7. Sascha Nowak uploaded patch set 6 CR +1 V +1 08/15/25, 05:50

  8. core-ci voted on patch set 6 V +1 08/15/25, 05:58 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/83438

  9. Andreas Kienast voted on patch set 6 CR +1 08/15/25, 06:36

  10. Christian Kuhn commented on patch set 6 08/15/25, 09:23

    this solution works. the drawback: we now "invent" cache tags (which are added to hash & page cache) only to transport the lifetime information, due to our current api that combines both. these tags have no other job than that and also can't be used for eviction, which is their real use case.
  11. Christian Kuhn commented on patch set 6 08/15/25, 09:44

    Reply

    looking at this a bit closer, i wonder if we can't simply call 'frontend.cache.collector'->restrictMaximumLifetime() if there are no tags in TS but only key and lifetime, which should reduce lifetime of the page cache - similar to what benni proposed in set 1 already?
  12. Sascha Nowak uploaded patch set 7 CR +1 V +1 08/15/25, 14:41

  13. Sascha Nowak commented on patch set 7 08/15/25, 14:43

    Reply

    Done
  14. core-ci voted on patch set 7 V -1 08/15/25, 14:50 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/83463

  15. Sascha Nowak uploaded patch set 8 V -1 08/18/25, 05:27

  16. core-ci voted on patch set 8 V +1 08/18/25, 05:34 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/83554

  17. Jörg Bösche voted on patch set 8 CR +1 08/18/25, 10:14

  18. Christian Kuhn commented on patch set 8 08/18/25, 10:42

    test main: page = PAGE page.10 = TEXT page.10.value = <h3>Benni in default</h3><br> page.20 = TEXT page.20.date = Y-m-d H:i:s page.20.cache.key = mykey page.20.cache.lifetime = 30 -> page cache with 'casual' tags is generated, lifetime 30 seconds, hash cache row is generated, no tags, lifetime 30 seconds. -> quick reload: content delivered from cache -> reload after 30 seconds: contend recreated, new cache rows. --> all good. test main: page = PAGE page.10 = TEXT page.10.value = <h3>Benni in default</h3><br> page.20 = TEXT page.20.date = Y-m-d H:i:s page.20.cache.key = mykey page.20.cache.tags = foo_1, foo_2 page.20.cache.lifetime = 30 -> page cache with the two additional tags is created, lifetime 30 seconds, hash cache row i generated, the two tags, lifetime 30 seconds -> quick reload: content delivered from cache -> reload after 30 seconds: content recreated, new cache rows. --> all good.
  19. Christian Kuhn commented on patch set 8 CR +1 V +1 08/18/25, 10:48

    Reply

    same result in v13
  20. Sascha Nowak voted on patch set 8 CR +1 V +1 08/18/25, 11:16

  21. Stefan Bürk commented on patch set 8 CR -1 08/18/25, 11:42

    Reviewing ...
  22. Stefan Bürk voted on patch set 8 CR +1 V +1 08/18/25, 12:33

  23. Christian Kuhn voted on patch set 8 CR +2 V +2 08/18/25, 12:33

  24. Christian Kuhn commented on patch set 8 08/18/25, 12:34

    Reply

    Done
  25. Christian Kuhn merged patch set 9 08/18/25, 12:55