Posts tagged cache

Should you use Memcache if you are already using Opcache?

Caching systems play a pretty important role in optimizing website performance, these work by storing frequently accessed data or resources in memory or disk, reducing the need to fetch them from the server or database repeatedly, this is of course on the server side, externally you can always cache with CDN (content distribution network) or other type of worker systems (these can do calculations), the combination of these both internal and external caching systems enhance website responsiveness, reduce server load, and improve scalability, contributing to a smoother user experience, and thats what we all want, right!

Im talking about this because I’ve been a big fan of Memcache/Memcached for years, but with opcache im kinda in the fence if i need to keep using both, because both do the same thing in different ways as well as different things all at the same time, in the sense that they overlap quite a bit and as we all know a caching system is useful to the point that it adds noticeable more performance for little extra resources, if it’s just adding a bit more performance, then its adding more complexity and less overall performance (since the caching system to work needs to use resources as well), so let’s check both of these caching systems, and see if you reach the same conclusion i did:

OPCache

    • OPCache is a bytecode cache for PHP scripts. It caches compiled PHP code in memory, which helps in speeding up the execution of PHP scripts by avoiding the need for PHP to recompile the scripts on each request.
    • OPCache improves PHP performance by reducing the time required for parsing and compiling PHP scripts.
    • OPCache is primarily focused on optimizing the performance of PHP code execution.

Memcache

    • Memcache, on the other hand, is a distributed memory caching system. It is used to store key-value pairs in memory across multiple servers.
    • Memcache is often used to cache data that is frequently accessed or that doesn’t change frequently.
    • Memcache is primarily focused on caching data from a database or expensive computation results, thus reducing the load on the database and improving overall application performance.

So now, regarding whether you should use Memcache if you’re already using OPCache, this is kinda the way i see it:

  • You can still use both:
    • If your application has a need for caching data that doesn’t change frequently, or if you want to reduce the load on your database by caching frequently accessed data, then using Memcache alongside OPCache can be beneficial.
    • OPCache will optimize the execution of your PHP scripts, while Memcache can cache data to improve overall application performance.
  • Maybe it’s not really required:
    • However, if your application doesn’t have a significant need for caching data or if it’s a small-scale application where caching data in memory isn’t critical, you might not need to incorporate Memcache, also of course if you don’t use a database then Memcache has less uses.
    • While OPCache alone can still provide performance benefits by caching and reusing compiled PHP scripts.

So in that sense seems like in a vacuum more often than not it’s best to use both, you use OPcache to cache php and then use Memcache to cache database data and computations, however that is in a vacuum, when you have other caching like nginx/litespeed/server side caching, local page caching, cdn’s like cloudflare, i kinda have a sense that both opcache and memcache give you just a small boost, so the more important point i guess it’s that it depends a lot on your site and application needs.

Let’s say if you have a normal well cached wordpress site (cache plugin and maybe cloudflare), thats updated daily im not sure you really need opcache and memcache, at all, but if i had to choose i would go with opcache since it seems the more light of the two and also not all requests are to the database (ie there are always way more php requests than database requests), but if i have a site or app that cant be cached often, then yes having both running seems like the best choice, even if i still caching locally or with a cdn, hope this made sense hahaha 🙂

WP Super Cache Vs W3 Total Cache Vs WP Fastest Cache Vs Hyper Cache Vs Quick Cache Vs Wordfence Security

Yes i know plenty of wordpress cache plugins comparisons posts, but i went around checking those and most are just a matter of opinion and taste or had some good data on performance both on the frontend and the backend of wordpress, my sites tend to have some optimisations built in mostly on the server so even with plugin there is some cache going on both on php and mysql as well as using nginx as a reverse proxy for the static files.

So i went ahead and made a basic wordpress site with one of the official themes and some random content, good enough, then checked some of the memory consumption and speed inside wordpress with the P3 Plugin and used Gtmatrix and Google Pagespeed to check the performance on the page, i also checked server side but as far as i can tell all the plugins didn’t use enough resources to be negligible, so what are my findings:

Performance Comparison of WordPress Cache Plugins

Cache Plugin Memory (sec) Speed Size (KB) Requests Pagespeed
No Plugin 0 5.49 965 32 75/100
WP Super Cache 0.084 5.0 962 33 75/100
W3 Total Cache 3.6 11.33 965 33 75/100
WP Fastest Cache 0.083 4.7 757 30 90/100
Hyper Cache 0.008 5.0 961 32 75/100
Hyper Cache + Autoptimize 0.097 6.7 690 24 90/100
Quick Cache 0.04 4.93 961 32 75/100
Quick Cache + Autoptimize 0.1 5.44 696 24 91/100
Wordfence Basic 0.15 6.97 965 33 75/100
Wordfence Falcon Engine 0.14 5.63 762 34 90/100

Notes: I’ve added Autoptimize to the cache plugins that don’t have the ability to combine and minify code, to see if it helped. Also note that all of these results besides pagespeed are averages i did test 3 times to make sure, although gtmatrix does use random servers to check so the speed part can be a bit off, so dont take it literally its more important the size and requests as well as overall pagespeed ranking for true performance, yes i know i could have used a fixed server but i wanted a more normal usage scenario.

No Plugin

Like i said above by default my sites work and cache well enough to rate a standard 75/100 on Pagespeed, also enabling by default gzip and other small wordpress tweaks help too, still its only here as reference point, of course most wordpress sites would rate a bit lower.

WP Super Cache

I’ve used it a lot in the past, still i’ve moved on to other cache plugins because its a bit like W3 Total Cache, it has become with time less user-friendly, from all the plugins it was the most troublesome to turn on and to turn off (leaves a lot of stuff behind) also with default settings it didn’t cache much, also one of the reasons i left was that sometimes updates would kill my sites, its still a standard but i think its not good enough anymore.

W3 Total Cache

This one is WP Super Cache on steroids, im sure its awesome since it has everything and then some, and although a bit easier to setup than it used to be, its kinda one that need a lot, i mean A LOT of pampering, it should only be used on large sites and sites where you control the server side and can enable the caches that W3 will use, also on my test and with default settings on it clearly was the worst plugin of them all, probably cause i should have changed something somewhere.

WP Fastest Cache

Although this plugin kinda broke a part of the wordpress backend (probably a css out of place), it was one of the most complete and simple plugins and you can see that it did a pretty good job and i didn’t even enable all the functions, it incorporates pretty much everything you expect in a small package, however 2 things keep me from using it, first there is no control over the html/js/css minify, and from my experience most my sites would break if i cant tweak this (Autoptimize does give you that control) the second is that the panel tries to ping ipinfo.io i don’t like plugins that do stuff like that.

Hyper Cache

The one I’m currently using on most of my sites, its simple clean and to the point and as you can see it does its job, besides one nagging issue when the plugin or wordpress updates the plugin seems to stop working and you get the “You must save the options since some files must be updated.” still unlike WP Super Cache the site doesn’t stop working, so it a safe and good plugin with very low memory consumption.

Quick Cache

I like this one, its has a nice panel, its simple and it worked just fine, still some of its best features are hidden away for a premium package and well that makes it under perform, i would understand if these features were more high end stuff like using CDN’s or tweaks around server side, but things like minify should be part of the basic feature set and as such this plugin is comparable with Hyper Cache but with more resource usage.

Extras to Consider

Wordfence Security

Its mostly a security/firewall plugin for your site that also has a caching plugin built in, so why not try it out, it has 2 settings so i tried them both, the basic and their so called falcon engine, i did see a improvement and it worked fine, still its of course a much bigger plugin that does a lot of things besides the caching, but if you are looking for both a security plugin and a cache plugin, this might be good for you.

Autoptimize

Its a plugin that minifies html/css/js and combines it, it can do it both on the head or move those scripts to the end of the body to help the page load, its also very flexible and you can skip files or tweak so it doesn’t break your site, some of the other plugins had these features or part of it, but this plugin gives you complete control and as such is a nice combination with other caching plugins.

So what was my choice?

Ill keep using Hyper Cache, it works well, the feature set is good enough and it doesn’t break my site ever, when i need to give a bit more i add Autoptimize or if its on Cloudflare i just tweak the html/css/js from there, it was my choice about a year ago when i move away from WP Super Cache and as far as i can tell it still was the best choice.