Docket Cache, Redis Or Memcached?
If you have looked into speeding up WordPress, you have probably come across Redis and Memcached. Docket Cache does the same job. All three are persistent object caches that let WordPress reuse previously cached data instead of querying the database again.
New to object caching? Start with Object Caching In Simple Terms.
WordPress can use only one of them at a time because it loads a single wp-content/object-cache.php file. So, which one is right for your site?
We make Docket Cache, but we believe in being honest. It is not the best choice for every site. This post compares the three and shows when each one makes sense.
How each one stores the cache#
Redis is a separate program that keeps data in memory. Your site talks to it over a network connection or a local socket. It is very fast, it can be shared by several web servers, and it can save its data to disk if that is turned on.
Memcached is also a separate program that keeps data in memory. It is simpler than Redis. It keeps data in memory only, so everything is lost when it restarts.
Docket Cache does not need a separate program. It saves each cached item as a small PHP file on disk. PHP's OPcache then keeps those files in memory, so most reads come straight from memory. See How Docket Cache stores and reads data for the details.
Side by side#
| Docket Cache | Redis | Memcached | |
|---|---|---|---|
| Where the cache lives | PHP files on disk, kept in memory by OPcache | In the memory of the Redis server | In the memory of the Memcached server |
| Extra program on the server | None | Redis | Memcached |
| PHP needs | Nothing extra, OPcache is recommended | A PHP extension such as PhpRedis, or the Predis library | The Memcached PHP extension |
| Works on shared hosting | Yes | Only if the host provides it | Only if the host provides it |
| Several web servers | Not recommended | Yes | Yes |
| After a restart | The files stay on disk | Kept only if saving to disk is turned on | Lost |
| Largest item | 3MB by default, up to 10MB | 512MB | 1MB by default |
| What runs out first | Disk activity and number of files | Memory | Memory |
When Docket Cache is the better choice#
- Your host does not offer Redis or Memcached. This is why we built Docket Cache. Redis is rarely included in low-cost and shared hosting plans. Docket Cache only needs PHP to be able to write files in
wp-content. - You run one server and a small to medium site. Docket Cache works well here, with no network connection to set up.
- You do not want to look after another program. There is nothing to install, start, watch or update on the server.
- You run many sites on one server. Each WordPress site keeps its cache in its own folder, so sites never read each other's cache. When several sites share one Redis server, each one needs its own key prefix to stay apart.
When Redis or Memcached is the better choice#
- Your host offers Redis. If your VPS or hosting plan has Redis, we recommend using it for better speed, especially as your traffic grows.
- You run a busy WooCommerce store, or a site with heavy traffic. Many visitors who are logged in, or who fill a basket, mean many cache writes. Redis handles this better.
- You run more than one web server. Each server would keep its own Docket Cache files, and they would go out of step. Redis or Memcached gives every server the same cache.
- Your site lives on network storage, such as NFS or Amazon EFS. Reading and writing small files over the network is slow.
- Your plan has very tight file or disk limits. Docket Cache uses one file for each cached item. You can limit how many files it keeps, as explained in Web Hosting I/O Usage, but a memory cache avoids the problem.
How to choose#
Switching between them#
Turn off the object cache in the old plugin first, so it removes its own object-cache.php file. Then turn on the new one. Some plugins add their own object cache too. For example, LiteSpeed Cache has an Object Cache option that you need to turn off before you use Docket Cache.
You do not need to move any data. A new object cache starts empty and fills itself as your site is used.
Whichever one you choose, a persistent object cache makes WordPress faster than no object cache at all. If your host does not give you Redis, Docket Cache is there for you, and it is free.