We are using an object cache backed by memcached, however I think that WordPress will still connect to MySQL on every page load, which shouldn't be needed if all queries can be handled by the object cache, right?

The problem this gives is that I still need to scale the MySQL server to be able to handle many connections at the same time even though there aren't many queries executed at all, so it sounds like a big waste. The problem is extra problematic on my setup because my pages need data from external APIs, so the pageloading times will be higher than usual, during which time the connection will just be sleeping on the MySQL database and wasting a spot.

Any tips on how to solve this? In an ideal scenario there shouldn't be any MySQL connections made until/unless an actual MySQL query has to be run on the database.

1 Answer 1


I'm currently dealing with a site using W3TC plugin and that plugin seems to provide a custom database handler which actually caches queries to memcache. Give that a try.

Sidenote: Just make sure, in case you are using multiple production servers, to use a shared memcache server and that you don't cache those queries on local memcache server (that's what my site is doing and you'll agree that it is not clever).

Further, I don't think that trying to reproduce MySQL query cache in memcache is a good idea. MySQL database handles query cache by default and it's performant enough.

What I'd do is a page level cache for non logged users. If you'll serve generated HTML from memcache rather than trying to build the output from scratch every time, despite it's object cached, you'll save even that mysql connection as there is no server side work required.

I'm not a fan of W3TC, but in this case, that plugin can provide you with page level cache as well.

  • Unfortunately I don't think I can use W3TC considering I'm using Heroku and I haven't found out a way to add their configuration settings file into my git repo. Also can't really use a page cache as there's just too many different pages and hits are generally not on the same page in a short time.
    – gamedancer
    Oct 1, 2014 at 15:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.