Any chance to make Cache Key feature available for Pro plans?

I’m having a Page Rule with Browser Cache TTL. Works fine, however, my site is using a language cookie for multi-lingual support. Unfortunately, the cached content will be saved with user’s language of the first server hit, and then it’ll be served on the wrong language for other users. This is the only thing holding me back subscribe to the pro plan.

Considering it’s Enterprise Only, I highly doubt it’ll make the double jump down to Pro.

1 Like

Sad, I guess Cloudflare is not suitable for me then :frowning:

You could do it through Workers. It would add a cost of course ($0.5/million requests) but it’s a lot less than the cost of Enterprise haha

4 Likes

Do you have a link to a tutorial maybe?

No, this is something your team has to develop. You might find some examples on the internet, but none will accommodate your specific needs.

If it’s just Browser cache TTL, this is something you can control at the origin, then set Cloudflare to Respect Origin Headers.

2 Likes

I don’t have such an option, 2 minutes is the first. I guess it’s not part of the free tier, but I cannot find anything related in the docs either.

I am only the team :slight_smile: Checked the docs, looks straightforward, I give a try. Does workers affect performance much?

No, if anything, it’s going to increase the performance of your application unless it’s done poorly.

I think there is an easier and cheaper way to do this using Transform Rules, and will have less performance impact (if any) than using Workers.

If you append the value of http.request.accepted_languages[0] as a query parameter it will cause the cache to include that value in the cache key.

https://developers.cloudflare.com/firewall/cf-firewall-language/fields#field-http-request-accepted_languages

5 Likes

A quick example:

Obviously, adjust for you own situation.

1 Like

I understood the OP is using a cookie, not Accept-Language.

He could use http.request.cookies, but that of course would add the whole set of cookies and if there are others than the language that’s going to be a caching party :partyparrot:.

In that case, can’t the Transform Rule check for the cookie, then change the query string accordingly?

My understanding is such a logic can’t be implemented yet. Too many ifs and string checks. A Worker of course can do it.

Of course, I cannot read!

http.request.cookies["language"][0] should do the same trick.

EDIT:

No it will not.


Apparently http.request.cookies can be used in Header rewrite, but not in URL Rewrite.

3 Likes

I could have sworn your reply said something else.

Long term probably better to look for a solution for multi-lingual site other than using cookies. Browsers and users can block cookies these days, which will break your site’s functionality anyway.

2 Likes

Also, SEO is terrible with that solution. A language = path should be the standard.

2 Likes

combine a Transform header + URL rewrite URL? Provided the CF plan supports the field :slight_smile: