App for Cloudflare® Pro

App for Cloudflare® Pro 1.9.9

  • Item seller Item seller Shawn
  • Featured

Pre-Sale Questions About Caching

serdarwork

New member
Hello,

First of all, thank you for developing and maintaining such a brilliant plugin. I configure and optimize LEMP (Nginx, PHP-FPM, MariaDB) servers with Redis object caching to handle high-traffic client websites. Nginx works with WP Rocket to serve cached pages without calling PHP. Normally, I use Cloudflare APO for those websites. However, when they run huge social media campaigns, Cloudflare never serves a cached copy of a page. It always bypasses the cache due to the query strings, and this causes CPU issues.

Is it possible to force Cloudflare to cache selected query strings with the App for Cloudflare plugin?

Kind regards,
Serdar
 
Hello,

First of all, thank you for developing and maintaining such a brilliant plugin. I configure and optimize LEMP (Nginx, PHP-FPM, MariaDB) servers with Redis object caching to handle high-traffic client websites. Nginx works with WP Rocket to serve cached pages without calling PHP. Normally, I use Cloudflare APO for those websites. However, when they run huge social media campaigns, Cloudflare never serves a cached copy of a page. It always bypasses the cache due to the query strings, and this causes CPU issues.

Is it possible to force Cloudflare to cache selected query strings with the App for Cloudflare plugin?

Kind regards,
Serdar
The caching mechanism is at the network edge (meaning it doesn’t go back to the origin server to serve the cached content, so it can’t check any logic on the origin like something from a plugin). That being said, you can fine-tune the cache key. For example you can choose to ignore query parameters if your site doesn’t need them for other things (the cache would be the same regardless of query parameters).

If you need to be more granular, you can call out specific query parameters to ignore/always use for the cache key, but that does require an Enterprise plan in Cloudflare.

 
The caching mechanism is at the network edge (meaning it doesn’t go back to the origin server to serve the cached content
I’ve implemented server-side caching as a redundancy layer to efficiently process any requests that bypass the Cloudflare edge.

So, if it ignores query strings, then multiple query strings like ?pa_color=yellow and ?pa_color=pink will show the same content. Can we do something like this without an Enterprise plan?

- Ignore all the query strings and serve cache
- And bypass cache for selected query strings like ?pa_color...

Also, the cache lifespan can be set to 12 hours. Is it possible to extend the time?

Thank you so much for your help.
 
I’ve implemented server-side caching as a redundancy layer to efficiently process any requests that bypass the Cloudflare edge.

So, if it ignores query strings, then multiple query strings like ?pa_color=yellow and ?pa_color=pink will show the same content. Can we do something like this without an Enterprise plan?

- Ignore all the query strings and serve cache
- And bypass cache for selected query strings like ?pa_color...
Cloudflare does allow it, but only with their Enterprise plan. There isn't really a way to bypass Cloudflare's own requirement for certain things for certain plans they offer (it would be great if everything was available for no cost, but I suspect it would be hard for them to stay in business.. hah).

Also, the cache lifespan can be set to 12 hours. Is it possible to extend the time?

Thank you so much for your help.
It's not too difficult... internally there's some intricacies with WordPress' nonce_life (which is how long a WordPress nonce is valid for), so by default the options were kept less than that (weird things can happen to users if you are using things for guest users that use nonce validation (for example a contact form). Effectively the contact form validity "expires" after 24 hours (24 hours is the default time WordPress uses for nonce life).

First, you can add this to your WordPress config to make WordPress' nonce_life longer (it wants the time in seconds, so this example would make nonce values good for 30 days):

PHP:
$GLOBALS['nonce_life'] = function($length) {
    return 86400 * 30;
};

...this needs to be at least 1 hour (3600 seconds) longer than the highest value you have for selectable cache times.

The second part (allowing an easy way for you to set different cache times) has been added on this end, but it's not out yet. Will be part of App for Cloudflare 1.9.9. You can add this to WordPress config file:

PHP:
$GLOBALS['app_for_cf_cache_times'] = function($cacheTimes) {
    $cacheTimes[] = 86400 * 7;
    $cacheTimes[] = 86400 * 14;
    $cacheTimes[] = 86400 * 21;
    return $cacheTimes;
};

...like the first example, the values are in seconds, so that would add options for 7 days, 14 days, 21 days, etc.

Again, the app_for_cf_cache_times thing isn't in there yet, it will be part of 1.9.9.

FWIW - nothing you have asked about would need the Pro version of the plugin, this is all stuff in the free version, so it's not really pre-sale (just want to make sure you know that you don't need to buy anything for this).
 
Thank you so much, @digitalpoint. I'm going to implement exactly what you recommended.

I'll offer your plugin to my clients for the image features. So, I wanted to make sure the caching feature will work fine. Also, it's better than paying 5$/month for APO. Thank you again!
 
Back
Top