Want more timely Centmin Mod News Updates?
Become a Member

Wordpress WP Super Cache, KeyCDN Cache Enabler, Redis Cache User Agent Bypass for Wordpress

Discussion in 'Blogs & CMS usage' started by eva2000, Dec 29, 2015.

  1. eva2000

    eva2000 Administrator Staff Member

    31,023
    6,925
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +10,431
    Local Time:
    6:54 PM
    Nginx 1.13.x
    MariaDB 5.5
    With WP Super Cache, KeyCDN Cache Enabler, and Redis Cache methods for Wordpress caching, some times you want specific requests to bypass the front end respective caches. With Centmin Mod Nginx it's easy to do via setting up an Nginx mapping for $http_user_agent to a $bypass_cache variable and populating the map with user agent fields you want to set to a value of 1 to bypass cache or 0 to hit caching layer.

    To do this, add to nginx.conf http{} context the below nginx mapping where setting user agent to 1 allows that user agent http requests to bypass the below 3 outlined caching mechanisms for Wordpress. Setting to 0 allows those user agent requests to hit the front end respective caching layers in Wordpress.

    The example below sets loader.io or blitz.io load testing services' http request user agent to a value of 1 to bypass the below respective Wordpress caching layers. Useful if you want to test before and after enabling caching for Wordpress :)
    Code:
    map $http_user_agent $bypass_cache {
        default                 0;
        "~blitz.io"             1;
        "~loader.io"            1;
        "~Siege"                1;
        "~ApacheBench"          1;
    }
    
    For Redis caching of Wordpress at Nginx level outlined at community.centminmod.com/posts/18828/, in /usr/local/nginx/conf/wpincludes/newdomain.com/rediscache_newdomain.com.conf include file add an extra entry to allow specific user agents to bypass Redis Caching if needed
    Code:
        if ($bypass_cache = 1) {
            set $skip_cache 1;
        }
    
    For Wordpress Super Cache plugin for centmin.sh menu option 22 auto installed Wordpress outlined at centminmod.com/nginx-wordpress-installer.html, in /usr/local/nginx/conf/wpincludes/newdomain.com/wpsupercache_newdomain.com.conf include file add an extra entry to allow specific user agents to bypass WP Super Cache if needed
    Code:
        if ($bypass_cache = 1) {
            set $cache_uri 'null cache';
        }
    
    For KeyCDN Cache Enabler plugin outlined at community.centminmod.com/threads/wp-cacher-enabler-plugin-by-keycdn-folks.5107/, in /usr/local/nginx/conf/wpincludes/newdomain.com/wpcacheenabler_domain1.com.conf include file add an extra entry to allow specific user agents to bypass Cache Enabler if needed
    Code:
        if ($bypass_cache = 1) {
            set $cache_uri 'null cache';
        }
    
     
    Last edited: Mar 17, 2017
    • Like Like x 2