Feature request: Allow to disable cache for route
hello,
I'd like to ask how to uncache specific resource. Lets say we have config like below. As far as i understand I should set -1 to not cache resource.
plugin.tx_rest.settings {
cacheLifeTime = 1728000
expiresHeaderLifeTime = 900
paths {
ins-hotels-hotels {
path = hotels
read = allow
write = deny
handlerClass = \Ins\Hotels\Rest\HotelHandler
cacheLifeTime = -1
}
Then in CacheFactroy.php we have function:
private function getCacheLifetime(
ConfigurationProviderInterface $configurationProvider,
ResourceType $resourceType
): int {
$resourceConfiguration = $configurationProvider->getResourceConfiguration($resourceType);
$cacheLifetime = $resourceConfiguration->getCacheLifetime();
if ($cacheLifetime > -1) {
return $cacheLifetime;
}
$cacheLifetime = $configurationProvider->getSetting('cacheLifeTime');
if ($cacheLifetime !== null) {
return (int)$cacheLifetime;
}
$cacheLifetime = $configurationProvider->getSetting('cacheLifetime');
if ($cacheLifetime !== null) {
return (int)$cacheLifetime;
}
return -1;
}
But with cacheLifeTime = -1 set in resource this condition will not match:
if ($cacheLifetime > -1) {
return $cacheLifetime;
}
and later it will return the default value for cacheLifeTime. So looks like this make impossible to uncache resource if we have defined fallback values.
Maybe I am getting that wrong but changing condition to:
if ($cacheLifetime >= -1) {
return $cacheLifetime;
}
would solve the problem.
I would be glad to hear your opinion. Tnx!
Thank you for opening this issue. I think you are right and this is a missing feature.
Changing only the condition you mentioned would not be enough, since the default value of getCacheLifetime() is -1. So the change would break the current behavior.
Maybe a cleaner approach would be to set NULL for getCacheLifetime() if no value is configured in TypoScript. But this will be a breaking change too.
A possible workaround for your case could be to set the lifetime to 1 second. Or the cleaner solution: remove the default cacheLifeTime from your TypoScript and add it to each route (although this may be a lot of work :-/ )
You right. There is no easy solution. What I probably do will be to remove default cacheLifetime and set up all individually. I have not so many resources defined.
Tnx for fast response! :)
Let's keep the issue open. Maybe one day I'll find the time to look into it :)