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

Cache get bypassed when using dynamic cookies #204

Closed
fidoboy opened this issue Oct 12, 2023 · 7 comments
Closed

Cache get bypassed when using dynamic cookies #204

fidoboy opened this issue Oct 12, 2023 · 7 comments
Labels
details needed Please clarify the situation by adding details.

Comments

@fidoboy
Copy link

fidoboy commented Oct 12, 2023

In WP Rocket you can setup the use of dynamic cookies to serve from a different cache with a plugin or custom code (in functions.php). For example a cookie where the language code is stored. The procedure works very well and the files are beign created into the cache folder using the cookie value appended to the filename as expected. But the rocket-nginx ignores this and always returns BYPASS into the X-Rocket-Nginx-Serving-Static header. How can I setup rocket-nginx to use this special cookie values?

More info about this feature here: https://docs.wp-rocket.me/article/1313-create-different-cache-files-with-dynamic-and-mandatory-cookies

Thanks in advance,

@maximejobin
Copy link
Collaborator

This can be achieved by adding custom Nginx code in the "start" configuration file (https://github.com/SatelliteWP/rocket-nginx#before-rocket-nginx-starts). You might want to modify the $rocket_dynamic variable to achieve your goal.

We've done this in the past for a client. We would have to know the specific rules to code it for you. Unfortunately, this is "out of scope" for Rocket-Nginx.

Feel free to contact SatelliteWP for custom work if you have a budget for your project:
https://www.satellitewp.com/en/contact/

@fidoboy
Copy link
Author

fidoboy commented Oct 31, 2023

Well, in fact I can code it by myself. I was pointing it here because I was hoping a solution in next release, the same that you can add query args to bypass using the INI file.

@maximejobin
Copy link
Collaborator

It seems to me that the problem you are facing is specific to a plugin that use the same URL to display different content.

Yes, query args are supported. I also added support for dynamic file ending exactly for the case you are referring to!

Feel free to share your solution to the community.

@fidoboy
Copy link
Author

fidoboy commented Nov 2, 2023

That's what I was talking about. When there is a plugin that changes the HTML based on a cookie value it can be configured in WP Rocket to create separate caches. This can be solved also manually into the generated conf file by rocket-nginx. But however, the php rocket-parser doesn't use any parameter from the INI file, so it can't be solved that way. This can be done with query params, for example, to do the opposite; to use the same cache file ignoring the query param. So it could be very useful if next rocket-nginx release adds INI support for dynamic cookies also.

kind regards and keep up the wood work :)

@maximejobin
Copy link
Collaborator

But however, the php rocket-parser doesn't use any parameter from the INI file, so it can't be solved that way.

I do not understand what you mean here. The generated .conf file uses the parameters from rocket-nginx.ini to generate your .conf file. I'm sorry if there is something I'm not getting.

When there is a plugin that changes the HTML based on a cookie value it can be configured in WP Rocket to create separate caches.

Yes. To do something similar with Rocket-Nginx, create a "start" file in the configuration folder for your website, get the cookie value using Nginx's $cookie_ pattern and then build the $rocket_dynamic variable according to your needs to read the right cached file in the WP Rocket's caching folder.

@fidoboy
Copy link
Author

fidoboy commented Nov 4, 2023

But however, the php rocket-parser doesn't use any parameter from the INI file, so it can't be solved that way.

I do not understand what you mean here. The generated .conf file uses the parameters from rocket-nginx.ini to generate your .conf file. I'm sorry if there is something I'm not getting.

When there is a plugin that changes the HTML based on a cookie value it can be configured in WP Rocket to create separate caches.

Yes. To do something similar with Rocket-Nginx, create a "start" file in the configuration folder for your website, get the cookie value using Nginx's $cookie_ pattern and then build the $rocket_dynamic variable according to your needs to read the right cached file in the WP Rocket's caching folder.

So that's the problem. Because there is not any parameter into rocket-nginx.ini to setup a dynamic cookie value. You can do it in next version, but it's not solved right now. I've solved it manually, by editing by hand the generated default.conf file. I've just suggested it here as an enhancement, because your code seems unfinished. There is a var for the dynamic cookie into the code, but it's unused.

@maximejobin
Copy link
Collaborator

Is there a reason why you did not edit the variable to set the proper value you want in start.default.conf?

I'm not sure I understand the issue.

@maximejobin maximejobin reopened this Nov 7, 2023
@maximejobin maximejobin added the details needed Please clarify the situation by adding details. label Nov 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
details needed Please clarify the situation by adding details.
Projects
None yet
Development

No branches or pull requests

2 participants