Review main Abandoned

77894[FEATURE] Add method to change cache expiration

Sybille Peters CR 0 V 0 Hard +337 −17 updated 02/24/23, 15:57

Commit message

A new event SetPageCacheEvent is introduced, so that
extensions can modify the page cache expiration time
before the page cache is written.

Review

  • Code review CR 0
  • Verified V 0

Issues 1

Files 4

Review log 3749

Show 1824 earlier messages
  1. Sybille Peters uploaded patch set 1 02/17/23, 17:14

  2. Sybille Peters uploaded patch set 2 02/17/23, 17:17

  3. core-ci voted on patch set 2 V -1 02/17/23, 17:24 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/37850

  4. Sybille Peters uploaded patch set 3 V -1 02/17/23, 17:31

  5. core-ci voted on patch set 1 V -1 02/17/23, 17:36 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/37849

  6. core-ci voted on patch set 3 V +1 02/17/23, 17:38 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/37851

  7. Oliver Klee commented on patch set 3 02/17/23, 18:43

    TypoScriptFrontendController.php:1840

    $timestamp is an int, not a bool. So the condition should be: if ($timestamp === 0) {
  8. Oliver Klee commented on patch set 3 02/18/23, 10:10

    TypoScriptFrontendController.php:1840 Reply

    (or <= 0, depending on what the intent is) Also, are negative numbers allowed for the $timestamp argument? If not, we should add a @param 0|positive-int $timestamp annotation so that PHPStan can help check this.
  9. Sybille Peters uploaded patch set 4 V +1 02/19/23, 10:25

  10. Sybille Peters commented on patch set 4 02/19/23, 10:26

    TypoScriptFrontendController.php:1840 Reply

    Done
  11. core-ci voted on patch set 4 V +1 02/19/23, 10:32 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/37868

  12. Oliver Klee commented on patch set 4 02/19/23, 11:09

    TypoScriptFrontendController.php:1847

    With the guard clause above (and the contract that no negative ints are allowed), this condition will always be true, and the else case is not needed.
  13. Sybille Peters commented on patch set 4 02/19/23, 11:16

    TypoScriptFrontendController.php:1847 Reply

    Well no, the $this->cacheExpires may be 0 in case it has not been initalized yet. The guard clause above checks $timestamp, not $this->cacheExpires. If I misunderstood something, please add code snippet, what you mean or push change.
  14. Oliver Klee commented on patch set 4 CR +1 02/19/23, 11:36

    TypoScriptFrontendController.php:1847 Reply

    Oh, I misread and was mistaken, and you're perfectly right. Thanks!
  15. Sybille Peters commented on patch set 4 02/19/23, 13:27

    TypoScriptFrontendController.php:1847 Reply

    Great 😊 Setting to resolved.
  16. Sybille Peters uploaded patch set 5 CR +1 V +1 02/19/23, 13:44

  17. core-ci voted on patch set 5 V +1 02/19/23, 13:51 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/37878

  18. Oliver Klee voted on patch set 5 CR +1 02/19/23, 14:06

  19. Guido Schmechel commented on patch set 5 02/20/23, 13:41

    I rather have a few questions for my understanding. In general, I still have the question why you decided against a PSR14 event? Sounds like a perfect use case for it to me. But maybe I'm missing something. :-)

    Feature-92535-AddMethodToChangePageCacheExpirationTime.rst:35

    2 minutes or 2 hours? The comment does not yet match the line below it

    TypoScriptFrontendController.php:1842

    What happens here if someone enters a negative integer? Is it treated like a 0 later on or does PHP throw an error? Oli had already mentioned this, but it's unclear to me how this is resolved. Maybe it's worth a sentence in the documentation?
  20. Sybille Peters uploaded patch set 6 CR +1 V +1 02/20/23, 18:14

  21. Sybille Peters commented on patch set 6 02/20/23, 18:17

    Reply

    It seemed like the straightforward solution and there was already the method addCacheTags. Creating an event seems a little complicated for this use case and there are already several hooks in TSFE as well as the mentioned addCacheTags. So we would add an event on top of this and can't really do any breaking changes right now. But now that you mention it, I think I will look into it and create another variant. I am not really sure at this point without implementing it if is such a bad idea. (The issue also mentions some of the possible solutions and the problem with the existing hooks)

    Feature-92535-AddMethodToChangePageCacheExpirationTime.rst:35 Reply

    done

    TypoScriptFrontendController.php:1842 Reply

    Because of the PHPDoc type hint I can't really check for negative values now without causing phpstan or PhpStorm to issue warnings. I think it would be better to check for <= 0 in the guard statement, but would have to give up the 0|positive-int in the PHPDoc.
  22. core-ci voted on patch set 6 V +1 02/20/23, 18:21 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/37906

  23. Oliver Klee voted on patch set 6 CR +1 02/20/23, 18:46

  24. Christoph Lehmann commented on patch set 6 02/20/23, 19:10

    TypoScriptFrontendController.php:1848

    Thanks for investigating in this issue. About this line: The core does not use \ in front of functions and the int cast is not needed, because min() with 2 integer arguments always returns an integer.
  1. Sybille Peters commented on patch set 6 CR -1 02/20/23, 19:21

    Working on alternative solution. Will be a while ...
  2. Sybille Peters uploaded patch set 7 CR +1 V +1 02/21/23, 16:41

  3. Sybille Peters commented on patch set 7 02/21/23, 16:44

    TypoScriptFrontendController.php:1848 Reply

    Thanks. You are right. It is now resolved. I modified the patch to use an Event. The functionality is now in then CacheMetadata class.
  4. Sybille Peters uploaded patch set 8 02/21/23, 16:47

  5. Sybille Peters commented on patch set 7 02/21/23, 16:49

    Reply

    Sorry, I already set this to resolved. It wasn't really. I now pushed my variant with the event. I also updated my example extension to use the event: https://github.com/sypets/sypets_example_plugincacheexpiration
  6. Sybille Peters uploaded patch set 9 02/21/23, 16:53

  7. core-ci voted on patch set 7 V -1 02/21/23, 17:03 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/37933

  8. core-ci voted on patch set 8 V -1 02/21/23, 17:04 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/37934

  9. Sybille Peters updated the commit message in patch set 10 02/21/23, 17:08

  10. Sybille Peters uploaded patch set 11 02/21/23, 17:13

  11. core-ci voted on patch set 9 V -1 02/21/23, 17:14 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/37935

  12. core-ci voted on patch set 10 V -1 02/21/23, 17:56 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/37938

  13. core-ci voted on patch set 11 V -1 02/21/23, 17:57 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/37939

  14. Sybille Peters uploaded patch set 12 V -1 02/21/23, 18:12

  15. core-ci voted on patch set 12 V +1 02/21/23, 18:18 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/37941

  16. Christoph Lehmann commented on patch set 12 02/21/23, 20:26

    Reply

    Can you both explain, why an event is better than the public function in TypoScriptFrontendController? I fully understand the code in the example extension, but i think an EventListener is too much overhead for this case. The public method would make it pretty simple. One line in a controller. No extra classes. No extra EventListener configuration. Another PSR7-friendly way would be to make this work (in a plugin action): return $response->withHeader('Cache-Control', 'max-age=3600'); This would also be a good step forward in the direction of having a content cache (if its gonna be realized in some years), where each content element might have its own cache life time.
  17. Christoph Lehmann commented on patch set 12 02/21/23, 21:32

    Reply

    This is just a draft for the PSR-7 way: https://review.typo3.org/c/Packages/TYPO3.CMS/+/77921 What do you think about it?
  18. Guido Schmechel commented on patch set 12 02/22/23, 00:04

    Reply

    The suggestion with the event came from me because I thought it gave us more flexibility. Example: A plugin generates a 3600 second lifetime, but something from outside influences the output again. Importer or other data changes, So I can conveniently control the lifetime. And I can also move the lifetime in both directions. I would see your PSR7 example as an add-on on top of that. That definitely has charm too :-)
  19. Sybille Peters commented on patch set 12 02/22/23, 03:51

    Reply Unresolved

    > Example: A plugin generates a 3600 second lifetime, but something from outside influences the output again. Importer or other data changes, So I can conveniently control the lifetime. Wouldn't for scenario with the importer none of the current implementations work? (if the page was already generated). Only something works which sets the expiration during page generation. The importer or whatever would just have to flush the cache. But I think you mean that Christoph's solution can only be used in a scenario where an object based on ResponseInterfacace is passed along, mainly in Extbase actions? However, the event does not give more flexibility currently compared to the solution of calling the function directly in TSFE. I implemented it because I thought it was a "cleaner" way than just calling the function directly
  20. Christian Kuhn commented on patch set 12 CR -1 02/22/23, 10:32

    i think the entire cache data should be extracted from tsfe and moved to a request attribute. i have something like that in mind for a while already - it would allow extracting getFromCache() to a middleware as well. however, i'm unsure if we'll be able to still get this done for v12. OTOH, i would *love* to not introduce new public methods in tsfe, thus my -1.
  21. Christian Kuhn commented on patch set 12 02/22/23, 10:33

    TypoScriptFrontendController.php:2003

    please no new cache related methods in tsfe.
  22. Sybille Peters commented on patch set 12 02/22/23, 11:36

    Reply

    Here too there is no new public function in the latest version. But if the entire cache handling should be refactored, the current patch probably makes little sense so you can keep the -1
  23. Christoph Lehmann commented on patch set 12 02/22/23, 12:01

    Reply Unresolved

    Do you have a little picture how it might be realized with a Middleware? How about marking the function internal, and go with https://review.typo3.org/c/Packages/TYPO3.CMS/+/77921 where we later can easily do a switch to a Middleware?

    TypoScriptFrontendController.php:2003 Reply

    How about marking it internal, and go with https://review.typo3.org/c/Packages/TYPO3.CMS/+/77921 where we later can easily
  24. Christoph Lehmann commented on patch set 12 02/22/23, 12:01

    TypoScriptFrontendController.php:2003 Reply

    Done
  25. Sybille Peters abandoned the change 02/24/23, 15:57

    Refactoring planned "entire cache data should be extracted from tsfe and moved to a request attribute." so approach does not make that much sense now or should be postponed.