# Server caching: Redis, Varnish and OPcache, what each one does

> OPcache, Redis and Varnish: what each server cache does, how they differ and how to combine them to speed up WordPress, WooCommerce and Laravel.

URL: https://codegea.com/en/server-caching-redis-varnish-and-opcache-what-each-one-does
Servers · 2026-08-17 · Derian Pinto

When a website is slow, the first reflex is to blame the hosting or install a cache plugin and cross your fingers. But "cache" is not a single thing: on a server several layers coexist that store already computed results so work is not repeated. Three of the most important are OPcache, Redis and Varnish, and although all three cache, each one solves a different problem. Understanding which does what is the difference between truly optimizing and poking around blindly.

I will explain it without smoke, focusing on what each one stores and when it suits you, so you know what to ask for or what to check on your server.

> OPcache speeds up PHP, Redis avoids going to the database and Varnish serves whole pages without touching PHP. They do not compete: they complement each other.

## Why caching is the most profitable lever

Generating a dynamic page, whether in WordPress, Laravel or whatever you use, means running code, querying the database and building the HTML on every visit. A cache stores the result of that work to reuse it. It is, by far, the improvement with the best effort-to-result ratio, and it connects directly to your [web performance](/en/supercharge-your-website-key-tips-for-web-performance-optimization) and, by extension, to your Core Web Vitals.

## OPcache: caches compiled PHP

PHP is an interpreted language: on every request it reads the file, compiles it into internal instructions (opcodes) and only then runs it. OPcache keeps those already compiled opcodes in memory, so PHP skips the compile step on every visit. It is the most basic cache and should almost always be on. It does not store data or HTML: only compiled code.

Checking whether it is active and whether Redis responds takes a couple of commands:

```bash
# Check whether OPcache is active
php -m | grep -i opcache
# Test the Redis connection
redis-cli ping
```

## Redis: caches data and queries

Redis is a key-value store that lives in memory. In WordPress it is used as an object cache: it stores the results of database queries and objects that would otherwise have to be recalculated on every load. In Laravel it is used for cache, sessions and queues. What it avoids is hammering MySQL over and over with the same queries, which is one of the most common bottlenecks on sites with traffic.

In WordPress, enabling Redis as an object cache usually starts with a few lines in `wp-config.php` and a plugin that acts as the bridge:

```php
define('WP_REDIS_HOST', '127.0.0.1');
define('WP_REDIS_PORT', 6379);
define('WP_CACHE', true);
```

## Varnish: caches whole pages

Varnish is an HTTP accelerator placed in front of your web server. It stores the full HTML response and serves it to the following visitors without touching PHP or the database. For content that does not change every second (blogs, corporate sites, catalogs) it is brutal: millisecond responses even with thousands of visits. The challenge appears with personalized content, carts or private areas, where routes must be excluded so one user is not served another’s page.

## The three at a glance

| Layer | What it stores | Where it acts | Shines in |
| --- | --- | --- | --- |
| OPcache | Compiled PHP code (opcodes) | Inside PHP itself | Any PHP site, always |
| Redis | Data, objects, queries and sessions | Between the app and the database | WordPress with many queries, Laravel, APIs |
| Varnish | Full HTML pages | In front of the web server | Heavy traffic and slowly changing content |

## What about plugin page caching?

Plugins such as LiteSpeed Cache or WP Rocket also do page caching, like Varnish but from inside WordPress. On shared hosting it is usually your only option and works very well. On a VPS you have the freedom to combine: OPcache and Redis at server level, plus a page cache (Varnish or the plugin’s). You do not need to have them all; you need the ones your case calls for.

## How to combine them for your case

| Your case | Recommended combination |
| --- | --- |
| Blog or corporate site on WordPress | OPcache plus page cache (plugin or Varnish) |
| WooCommerce store | OPcache plus Redis (object cache) plus page cache with the cart and checkout excluded |
| Laravel application | OPcache plus Redis for cache, sessions and queues |
| Heavy traffic and stable content | All three: OPcache, Redis and Varnish |

## In my experience

In my experience, 80 percent of the benefit comes from the simplest things: enabling OPcache (often it is already there but poorly configured) and adding Redis as an object cache if the site runs many queries. I leave Varnish for when traffic justifies it, because its fine configuration, especially with carts and private areas, is more work than people think. And an important warning: caching hides problems, it does not cure them. If your site is slow because of badly written queries or an overloaded server, fix that first. A well-placed cache on a healthy base flies; on a broken base it only disguises. All of this, of course, lives or dies with good [server maintenance](/en/vps-server-maintenance-essential-monthly-checklist).

---

Do you have a VPS and do not know whether it is well used? At [Codegea](/en/contact) we configure and maintain servers with OPcache, Redis and Varnish tuned for WordPress, WooCommerce and Laravel, so your site runs fast without scares. Write to me and we will review it.
