Case insensitive caching using Page Rules

I am trying to reduce the load on my server.

When I am requesting CloudFlare starts caching the content for 60 seconds as intended. But when requesting or any other variant CloudFlare tells me ‘MISS’ and my server has to respond.

Is there a way to tell CloudFlare to ignore the letter casing or to put it all lowercase beforehand?

Thanks for any advice!

just tell cloudflare to cache everything with* in a page rule set to cache everything. If you do /test/t/t/t/t it will be a miss because it’s never been loaded before to be cached. After one request, it will be cached (usually)

1 Like

Thanks for your reply and it gets cached by Cloudflare but only for exactly that request. When you capitalize one of the letters, it’s missing the cache and requesting my server. After that request, it is cached by Cloudflare again. Until you capitalize another letter etc.

My current page rule:

There is nothing out of the box. The best way would be to unify the capitalisation already on the server side. If that is not possible, your only option would be to use a worker where you “normalise” the path.

1 Like

Yes, that’s exactly what I said. CloudFlare will cache it after it has been requested. As Sandro said, try to use a worker or fix something on the server side

1 Like

What do you mean by

to unify the capitalisation already on the server side

I have full access to the machine hosting my site but would not know any method to unify it. A worker sadly would be too expensive for this use-case.

By that I meant to ensure you are not generating URLs to your resources with different capitalisations in your pages.

Can’t really do that because the client has complete control over it. But thanks anyway!

That much web traffic isn’t going to harm your web server, do you have a bandwidth limit on the web server??

Not exactly - I am currently receiving about 4.000.000 requests a day on my endpoint and most of them won’t be cached at all because the requests for the same resource are ofter beyond the caching time.
But some endpoints get requested a couple of times but with different letter casing and I need to cache the response in memory because of that. My webserver is often making requests to a rate-limited service. Not caching my response would result in sending my clients error.

Because of the rise in requests, I had to optimize a lot and now my response times are getting bad at heavy peaks because I have to store most of it in my database instead of memory.

Why don’t you raise the caching time to a month or 2 weeks? CloudFlare cannot cache requests that have never been loaded before (Case sensitive). If you load NoTcH it is a MISS but if I load it again, it’s a HIT. Setup your API to redirect if there is caps in the name and redirect to the lowercase version.

Another way to fix if you use a HTML search page or a script to load the API is to add some code (Python, str.lower('NoTcH')) Which will return a ‘notch’, try to find it for the client you are using and fix it that way.

:wave: @sprax2013,

You can do this using Cloudflare workers.


I put the caching time as high as possible. Only the short-living ones are the ones I care about case sensitivity. In my example, it has to be cached for a minimum of 60 seconds but I may have changed during that period so I put it on 62 seconds.

Sadly the API is aimed at developers. My libraries and snippets already prepare the input as best as possible but most requests still are not. That’s why I said

Because my clients often are developers.

Depending on how important it is to you, I’d still look into workers. Based on the number of requests you mentioned that should be around $60 a month.

1 Like

This topic was automatically closed after 31 days. New replies are no longer allowed.