Join the community today
Register Now

Wordpress Warm Cache

Discussion in 'Blogs & CMS usage' started by JarylW, Oct 4, 2015.

  1. JarylW

    JarylW Active Member

    216
    41
    28
    Jun 19, 2014
    Singapore
    Ratings:
    +103
    Local Time:
    8:00 PM
    Found this plugin quite clever & useful so I thought I'd share.


    It automatically 'warms' your cache based on a sitemap your provide for it to crawl.
    After you put your sitemap (I use YOAST SEO's sitemap) and press 'Use this sitemap' a link is generated for you to use to prompt the crawler.
    warmcache.png
    If using centminmod menu option #22, you will see in

    [root@sone /]# crontab -e

    Code:
    0 */4 * * * /usr/bin/cminfo_updater
    */15 * * * * sleep 245s ; wget -O - -q -t 1 http://yoursite.com/wp-cron.php?doing_wp_cron=1 > /dev/null 2>&1
    0 */8 * * * sleep 269s ;/root/tools/wp_updater_yoursite.com.sh 2>/dev/null
    
    Add the generated URL below (this example is for hourly crawling)
    Code:
    0 */4 * * * /usr/bin/cminfo_updater
    */15 * * * * sleep 245s ; wget -O - -q -t 1 http://yoursite.com/wp-cron.php?doing_wp_cron=1 > /dev/null 2>&1
    0 */8 * * * sleep 269s ;/root/tools/wp_updater_yoursite.com.sh 2>/dev/null
    0 * * * * wget -O /dev/null https://www.yoursite.com/?warm_cache=QFNGVTCs
    
    Viola. Fast pages everytime.
     
  2. rdan

    rdan Well-Known Member

    5,451
    1,412
    113
    May 25, 2014
    Ratings:
    +2,206
    Local Time:
    8:00 PM
    Mainline
    10.2
    WP-Super-Cache has something similar by default, without any complicated setup.
     
  3. eva2000

    eva2000 Administrator Staff Member

    55,404
    12,256
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +18,836
    Local Time:
    10:00 PM
    Nginx 1.27.x
    MariaDB 10.x/11.4+
    Very nice if you use redis caching. WP Super Cache has cache preloading in it's advance feature set you can enable
     
  4. JarylW

    JarylW Active Member

    216
    41
    28
    Jun 19, 2014
    Singapore
    Ratings:
    +103
    Local Time:
    8:00 PM
    Yup. Does super cache preload cached pages using wp cron?

    Yes i am using redis nginx cache as per your recommendation at the moment. Only gripe is no proper way to implement CDN.. I think rtcamp recommends using nginx addon for this
     
  5. eva2000

    eva2000 Administrator Staff Member

    55,404
    12,256
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +18,836
    Local Time:
    10:00 PM
    Nginx 1.27.x
    MariaDB 10.x/11.4+
    yup or if done via centmin.sh menu option 22 then wp cron is disabled and a system cronjob is setup at system level
    ta da, FAQ 33 outlines CDN url replacement at Nginx level via sub filter FAQ - CentminMod.com LEMP Nginx web stack for CentOS :)

    Module ngx_http_sub_module
     
  6. JarylW

    JarylW Active Member

    216
    41
    28
    Jun 19, 2014
    Singapore
    Ratings:
    +103
    Local Time:
    8:00 PM
    Code:
    location / {
        sub_filter 'http://domain.com/wp-content/uploads/'  'http://cdn.domain.com/wp-content/uploads/';
        sub_filter_last_modified on;
        sub_filter_once off;
    }
    This did nothing for me. How did you get it working?

    Edit: put it in server block without '' and it worked
     
    Last edited: Oct 5, 2015
  7. eva2000

    eva2000 Administrator Staff Member

    55,404
    12,256
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +18,836
    Local Time:
    10:00 PM
    Nginx 1.27.x
    MariaDB 10.x/11.4+
    strange that's what docs say so you did

    outside of location in server block
    Code:
        sub_filter http://domain.com/wp-content/uploads/  http://cdn.domain.com/wp-content/uploads/;
        sub_filter_last_modified on;
        sub_filter_once off;
    yup confirmed same experience as you
     
    Last edited: Oct 5, 2015
  8. eva2000

    eva2000 Administrator Staff Member

    55,404
    12,256
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +18,836
    Local Time:
    10:00 PM
    Nginx 1.27.x
    MariaDB 10.x/11.4+
    seems this works though
    Code:
    location ~ /directory {
        sub_filter 'http://domain.com/wp-content/uploads/'  'http://cdn.domain.com/wp-content/uploads/';
        sub_filter_last_modified on;
        sub_filter_once off;
    }
     
  9. JarylW

    JarylW Active Member

    216
    41
    28
    Jun 19, 2014
    Singapore
    Ratings:
    +103
    Local Time:
    8:00 PM
    That's really weird. I decided to go with Cloudflare for WooCommerce setup and take advantage of Railgun that comes free with Dediserve.

    What is ironic is that I used cloudflare since the start. Long time before, rocket loader used to break about half of my wordpress sites, regardless of how basic they were.

    Now, with a complex WooCommerce with lots of jquery and god knows that, it cuts down HTTP requests by 3 times with all options enabled and load speed by almost 2x without breaking any functionality.

    The test location was Dallas (and my origin VPS is located in Singapore) is probably the secondary factor why using a service like Cloudflare would see such vast loading speed improvements.

    Without CF
    no-cf.jpg

    CF-Cache: Miss
    cf-miss.jpg

    Cf-Cache: Hit
    cf-hit.jpg


    Likewise, with local test location in webpagetest.

    Without CF
    wpt-nocf.jpg

    CF-Cache: HIT
    wpt-withcf.jpg
    The primary factor would be the aggregation and optimization by Rocket Loader. Themeforest themes use external references to an uncanny amount of javascript and css.

    With real world performance improvements and data like this I can't find a reason not to use CloudFlare.

    I've not used Cloudflare with wordpress for a while but not all themes will function normally.. I guess I got lucky :p
     
  10. JarylW

    JarylW Active Member

    216
    41
    28
    Jun 19, 2014
    Singapore
    Ratings:
    +103
    Local Time:
    8:00 PM
    Also, the Warm Cache wordpress plugin does not seem to like working with Cloudflare very much.

    I now use this open source cache warmer khromov/sitemap-cache-warmer ยท GitHub

    Can be run on a separate VPS than your production environment but I just do it with the same.

    There's probably many ways to achieve this but here's how I do it.

    1) Upload github contents to /usr/local/nginx/html/cache-warmer/

    2) Edit /usr/local/nginx/conf/conf.d/virtual.conf file and add

    Code:
    location /cache-warmer/ {
    allow 127.0.0.1;
    deny all;
    }
    
    3) Edit /usr/local/nginx/html/cache-warmer/config.php and set key.

    Code:
        'key' => 'g835w7glkqweiw90nqw' // Secret key to allow traversing sitemaps
    3) Append to crontab

    Code:
    0 * * * * curl --ciphers ecdhe_ecdsa_aes_128_sha "http://127.0.0.1/cache-warmer/warm.php?key=g835w7glkqweiw90nqw&url=https://sitetocrawl.com/sitemap_index.xml&sleep=0" >/dev/null 2>&1
    
    
     
    Last edited: Oct 6, 2015