Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In CloudFlare, present cached page only if cookie is not set

I'm trying to prevent CloudFlare from hitting our servers if a user is not logged in, but instead to get the cached object if possible. We're setting a cookie ('email') if the user is logged in, and clearing it when the user is logged out.

Is this possible?

like image 967
StackOverflowed Avatar asked Oct 29 '25 16:10

StackOverflowed


1 Answers

In order to do this you can use a feature called "Bypass Cache on Cookie". This allows you to specify a Regex string of what type of cookie you want to Bypass:

Bypass Cache on Cookie

When used in conjunction with a Cache Everything Page Rule, you can use this setting to cache anonymous page views but bypass the cache when a cookie exists.

Further reading:

  • Caching Anonymous Page Views
  • How do I cache static HTML?
  • Technical Details: Bypass Cache Cookie (Business and Enterprise Only)
like image 156
mjsa Avatar answered Nov 01 '25 14:11

mjsa