77894[FEATURE] Add method to change cache expiration
Commit message
Review
-
Code review CR 0
-
Verified V 0
Issues 1
Files 4
- typo3/sysext/core/Documentation/Changelog/12.3/Feature-92535-Psr14EventToChangePageCacheExpirationAndAddTags.rstnew+128 −0
- typo3/sysext/frontend/Classes/Cache/CacheMetadata.phpnew+68 −0
- typo3/sysext/frontend/Classes/Controller/TypoScriptFrontendController.php14+69 −17
- typo3/sysext/frontend/Classes/Event/SetPageCacheEvent.phpnew+72 −0
Review log 3749
Show 1824 earlier messages
-
Sybille Peters uploaded patch set 1 02/17/23, 17:14
-
Sybille Peters uploaded patch set 2 02/17/23, 17:17
-
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
-
Sybille Peters uploaded patch set 3
V -102/17/23, 17:31 -
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
-
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
-
Oliver Klee commented on patch set 3 02/17/23, 18:43
-
Oliver Klee commented on patch set 3 02/18/23, 10:10
TypoScriptFrontendController.php:1840Reply(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. -
Sybille Peters uploaded patch set 4
V +102/19/23, 10:25 -
Sybille Peters commented on patch set 4 02/19/23, 10:26
TypoScriptFrontendController.php:1840ReplyDone -
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
-
Oliver Klee commented on patch set 4 02/19/23, 11:09
TypoScriptFrontendController.php:1847With 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. -
Sybille Peters commented on patch set 4 02/19/23, 11:16
TypoScriptFrontendController.php:1847ReplyWell 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. -
Oliver Klee commented on patch set 4 CR +1 02/19/23, 11:36
TypoScriptFrontendController.php:1847ReplyOh, I misread and was mistaken, and you're perfectly right. Thanks! -
Sybille Peters commented on patch set 4 02/19/23, 13:27
TypoScriptFrontendController.php:1847ReplyGreat 😊 Setting to resolved. -
Sybille Peters uploaded patch set 5
CR +1V +102/19/23, 13:44 -
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
-
Oliver Klee voted on patch set 5 CR +1 02/19/23, 14:06
-
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:352 minutes or 2 hours? The comment does not yet match the line below itTypoScriptFrontendController.php:1842What 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? -
Sybille Peters uploaded patch set 6
CR +1V +102/20/23, 18:14 -
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:35ReplydoneTypoScriptFrontendController.php:1842ReplyBecause 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. -
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
-
Oliver Klee voted on patch set 6 CR +1 02/20/23, 18:46
-
Christoph Lehmann commented on patch set 6 02/20/23, 19:10
TypoScriptFrontendController.php:1848Thanks 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.
-
Sybille Peters commented on patch set 6 CR -1 02/20/23, 19:21
Working on alternative solution. Will be a while ... -
Sybille Peters uploaded patch set 7
CR +1V +102/21/23, 16:41 -
Sybille Peters commented on patch set 7 02/21/23, 16:44
TypoScriptFrontendController.php:1848ReplyThanks. You are right. It is now resolved. I modified the patch to use an Event. The functionality is now in then CacheMetadata class. -
Sybille Peters uploaded patch set 8 02/21/23, 16:47
-
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 -
Sybille Peters uploaded patch set 9 02/21/23, 16:53
-
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
-
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
-
Sybille Peters updated the commit message in patch set 10 02/21/23, 17:08
-
Sybille Peters uploaded patch set 11 02/21/23, 17:13
-
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
-
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
-
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
-
Sybille Peters uploaded patch set 12
V -102/21/23, 18:12 -
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
-
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. -
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? -
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 :-) -
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 -
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. -
Christian Kuhn commented on patch set 12 02/22/23, 10:33
TypoScriptFrontendController.php:2003please no new cache related methods in tsfe. -
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 -
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:2003ReplyHow about marking it internal, and go with https://review.typo3.org/c/Packages/TYPO3.CMS/+/77921 where we later can easily -
Christoph Lehmann commented on patch set 12 02/22/23, 12:01
TypoScriptFrontendController.php:2003ReplyDone -
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.
TypoScriptFrontendController.php:1840