rest icon indicating copy to clipboard operation
rest copied to clipboard

Feature request: Allow to disable cache for route

Open kszymukowicz opened this issue 6 months ago • 3 comments

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!

kszymukowicz avatar Dec 11 '23 12:12 kszymukowicz