Best Caching Practices

You’d need to install the batcache + WP memcached plugin yourself and set some constants in WP config. But other than that it’s all ready to go. The plugins default to the standard local memcached settings so you don’t need to configure that unless you were going to use some external memcached instance.

Or the new kid on the block - http://wp-rocket.me/features/

I haven’t used it yet, but reading a lot from people who I trust that think it is epic win and worth the paid business model support.

I haven’t had much luck with any of the more comprehensive cacheing solutions. Most require some kind of setup that can’t be handled programmatically.

I can release my Varnish VCL - it’s fairly complex and has comprehensive conditional statements that control cache headers. I highly recommend Varnish over any of the WP cacheing solutions, as it can be controlled through configuration, which tends to make scaling and deployment much easier.

I don’t know if I’d say Varnish is “opinionated,” it just doesn’t have exceptions built in for WordPress. In fact, given the fact that it’s a blank slate out of box, I’d say it’s the reverse of “opinionated.” It does exactly what you tell it to do. Nothing more, nothing less. It’s extremely flexible and you can script it to do just about anything. We have it controlling cookies and headers as well.

I haven’t tried WP Rocket, but I have tried W3TC and Super Cache - and as I understand it, WP Rocket isn’t that far off conceptually.

Another nice thing about Varnish is that you can use it as a WAF (Web Application Firewall). There are VCLs that mimic OWASP mod_sec rules.

Also, be careful about the 1gb limit. To get the full benefit of Varnish, you’ll need to mallloc it, and you should give it plenty of overhead.

2 Likes

I would appreciate out the VCL for sure. I just moved hosts from DO to Media Temple, and have plenty of ram now to play with.

Here’s an older version that doesn’t have as many site specific rules in it. I need to go through and refactor this so it’s a clean VCL that I augment with site specific VCLs. Please don’t use this out of the box - it does need some care, and the rules need to refactored so you don’t have to pipe around them.

Hopefully this helps a bit. There’s a dearth of good source material for VCLs out there.

Again - this is not done and requires a good amount of work, but should give you a good headstart

1 Like

Further info on utilizing Varnish as a WAF

https://www.owasp.org/index.php/OWASP_VFW_Project

Don’t underestimate the power of being able to manipulate every header or cookie that passes through Varnish. Once that door opens, there’s little that you can’t do.

@brandon Also, instead of nginx handling the termination, you could use HAProxy, which would open up the possibility of horizontally scaling your installation later. Since WP uses cookie based sessions by default, horizontal scaling is fairly straightforward. HAProxy is also faster and more capable as a load balancer than nginx.

2 Likes

@brandon Here’s a simpler one I came across. https://github.com/BenHall/docker-varnish/blob/master/default.vcl

I’d use that as a base and go from there. I have a lot of troubleshooting headers that I add and header “conditioners” in there.

So does anyone have solutions for when something like Varnish is overkill? I’m a little hesitant to move to Memcached given a lack of clear instructions on setting up Batcache and Memcached Backend… and both plugins on WP.org being more than 2 years out of date. There is also the issue of creating advanced-cache.php (and possibly other config files) in app/ and how to handle those for deployments.

I work at a small university, for the most part caching is not necessary but I still like to have it setup for cases when some event or news item drives up a bunch of traffic randomly (think emergency situations - active shooter, fire, etc). I feel like Varnish and Memcached are both a little overkill and reach diminishing returns when it comes to setup and configuration compared to WP Super Cache and a properly configured Nginx. But WP Super Cache does not seem to fit into Bedrock since it populates the app/ directory with advanced-cache.php which may or may not change with new versions. I avoid W3TC as it is too complex and bloated. Super Cache provides a nice simple page cache, I just wish I could find a way to set it up with Bedrock so as to not destroy the principals behind the project.

I think you said you were using Apache but Nginx has built-in caching and it’s simple and amazing.

Here’s a good article on it: http://reviewsignal.com/blog/2014/06/25/40-million-hits-a-day-on-wordpress-using-a-10-vps/

Basically you just cache every page for a very short amount of time so you don’t need to worry about cache invalidation. Note that this only applies to users who aren’t logged in which is usually for traffic spikes.

3 Likes

So what is the recommended caching solution for Bedrock-Ansible?

Should I try Batcache or go with the article linked above and get the Nginx cache running?

Depends on use case. Nginx microcaching is simplest and most straight forward, but also not as performant since pages are re-generated every 30 seconds or whatever.

You can try starting with Nginx caching and see if its fine.

Hello @etc, Thank you for your VCL file, it works almost as expected.
However I can’t see how to cache (varnish/apache2) some pages, for example:

Can you help? :slight_smile: Thank you!

Did you change the VCL since you posted this? I checked both the pages, but they’re throwing the same headers it seems.

Which VCL did you end up using? Do you have the debug headers that I wrote in still?

Thank you for your Reply @etc .
I changed it. Yes. Because it was not being reliable.
I will activate it again tomorrow morning and will post back here.

Sorry for the trouble :blush:

Hello @etc , you can now check, sorry for the trouble.

Are you using the VCL I provided with a debug whitelist? If so, I might need to be added to it so I can see the debug headers.

I changed the group_var for caching to “true”

Can someone tell me which type of caching I turned on and how I would go about resetting/clearing the cache?

Thanks!

I think you’ll have very little to set up. See the trellis caching wiki:

The whole setup is “micro-cache” oriented, so there is no means [or need] of flushing the cache.

You can google more info on microcaching if you’re interested.

Hi there! I’m using a plugin (mobble) to send device specific views down the wire based on user agent. How is the microcaching going to affect the UA string detection? Have anybody tried this before?

Any help more than appreciated!