问题
i have a page with a TYPO3 plugin, that shows the "tip of the month". I populated items in the list module, having a start/end date to the respective month.
The thing is I have to either disable the cache (or set it to only 1 day) or flush it manually, or the tip of the last month is still shown.
I want the page to be cached, but the cache only be valid until the 1st of each month. Setting page lifetime in the background to "1 month", actually sets a lifetime of 2678400 seconds (31 days), which would not work on months shorter than 31 days. Or is there already a functionality behind it, calculating the actual length of the current month!? (I can't wait a full month to test it.)
I know there is cache.lifetime
available in TypoScript, but you can only set an integer (amount in seconds), "unlimited" (no expiration until flushed), "default" (as configured in config.cache_period) or stdWrap.
I know that the last created cache datetime is sent via "Date" header in the response. So TYPO3 should somewhere know this timestamp.
So I would need something like:
<?php
$dateStart = new DateTime( $pageLastCreated_whencever );
$dateEnd = new DateTime();
$dateEnd->modify( 'first day of +1 month' );
$dateDiff = $dateStart->diff($dateEnd);
return $dateDiff->format('%s'); // equals cache lifetime
?>
Could someone push me in the right direction?
I would love to avoid having to use a user function, though...
Thanks in advance.
回答1:
It doesn't harm to clear the cache in TYPO3 from time to time.
I would recommend to use config.cache_clearAtMidnight = 1 so you are sure that your update shows on the first of each month. Then you could use a schedular task to rebuild the cache right after clearing.
Edit
I looked a bit through the docs, and what you can definitely do is to wrap the cache_clearAtMidnight
in a typoscript condition that checks if the dayofmonth is smaller than two.
This would be your full typoscript that goes to your page setup. No php needed.
[dayofmonth < 2]
config.cache_clearAtMidnight = 1
[global]
回答2:
As you found out the cache time is done in seconds. The only solution would be to use a custom scheduler task which clears the cache by your needs
来源:https://stackoverflow.com/questions/38146675/set-typo3-page-cache-lifetime-to-an-exact-month-and-not-31-days