Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature request: Allow to disable cache for route #77

Open
kszymukowicz opened this issue Dec 11, 2023 · 3 comments
Open

Feature request: Allow to disable cache for route #77

kszymukowicz opened this issue Dec 11, 2023 · 3 comments

Comments

@kszymukowicz
Copy link

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!

@cundd
Copy link
Owner

cundd commented Dec 11, 2023

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 :-/ )

@kszymukowicz
Copy link
Author

kszymukowicz commented Dec 11, 2023

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! :)

@cundd cundd reopened this Dec 11, 2023
@cundd cundd changed the title how to uncache single resource Feature request: Allow to disable cache for route Dec 11, 2023
@cundd
Copy link
Owner

cundd commented Dec 11, 2023

Let's keep the issue open. Maybe one day I'll find the time to look into it :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants