Skip to content

Feature request: Allow to disable cache for route #77

@kszymukowicz

Description

@kszymukowicz

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!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions