A web server cache stores a copy of already-generated responses and delivers them directly to subsequent visitors, skipping the work of rebuilding them from scratch. The result: the server does far less work and pages load much faster.
If you've ever wondered why some sites open in milliseconds while others take several seconds, caching is a big part of the answer. This beginner's guide explains how it works, what types exist, and what you should configure.
Why Does Web Server Cache Exist?
When someone visits a page on your site, the server follows a chain of work: it reads the request, runs PHP (or another language), queries the database, builds the HTML, and sends the response. All that can take anywhere from 200 ms to several seconds.
If the same content will look identical for the next visitor — or the next thousand — why repeat all that work? Cache cuts the process short: the first time, the response is generated and saved; every subsequent time, it's delivered straight from temporary storage.
This reduces Time to First Byte (TTFB), relieves the database, and lets a modest hosting server handle thousands of simultaneous visits without breaking a sweat.
Types of Web Server Cache
Full-Page Cache
Stores the completely rendered HTML for a URL. This is the most effective type: the server reads a plain HTML file and sends it — no PHP execution, no database query. Tools like Varnish, NGINX FastCGI Cache, and WordPress plugins like WP Rocket implement this approach.
Object Cache
Stores in memory the results of frequent database queries or intermediate calculations (PHP objects, arrays, etc.). Redis and Memcached are the most common engines. The page is still generated dynamically, but it reuses already-retrieved data without querying the database again.
OPcache
PHP converts source code into bytecode every time it runs. OPcache stores that bytecode in memory so it doesn't have to recompile on every request. It's enabled by default in PHP 5.5+ and can cut PHP execution time by up to 70%.
HTTP Cache / Headers
This isn't cache inside the server — it's instructions the server sends to the browser (and intermediate proxies) about how long they can store a resource. Configured via headers like Cache-Control, Expires, and ETag. For a detailed look at the browser side, browse our web performance articles.
How the Cache Cycle Works, Step by Step
- Incoming request: the visitor's browser requests a URL from your server.
- Cache check: the server (or the cache engine in front of it) looks for a valid stored copy of that response.
- HIT or MISS:
- Cache HIT: a valid copy exists → it's delivered immediately, no code runs.
- Cache MISS: no copy or it expired → the full response is generated (PHP + DB), saved to cache, and delivered.
- TTL (Time to Live): every cache entry has a lifespan. When it expires, the next request generates a fresh copy.
- Invalidation: if content changes (new post, updated price), you can force deletion of the old copy before TTL expires. This is called purging or invalidating the cache.
| Cache Type | Where It Lives | What It Stores | Common Tools |
|---|---|---|---|
| Full-Page Cache | Disk or RAM on the server | Complete HTML for a URL | Varnish, NGINX, WP Rocket |
| Object Cache | Server RAM | DB results, PHP objects | Redis, Memcached |
| OPcache | Server RAM | Compiled PHP bytecode | PHP OPcache (built-in) |
| HTTP Cache | Browser / proxy | Static files (CSS, JS, images) | Cache-Control, ETag |
Basic Configuration Every Site Should Have
Enable OPcache in PHP
If your hosting uses cPanel or Plesk, OPcache is usually available in the PHP settings section. Make sure it's enabled and that opcache.memory_consumption is set to at least 128 MB.
Cache-Control Headers for Static Files
In Apache, add something like this to your .htaccess:
<FilesMatch "\.(jpg|jpeg|png|gif|webp|svg|css|js|woff2)$">
Header set Cache-Control "max-age=31536000, public, immutable"
</FilesMatch>
This tells the browser to store those files for a year. For changes to take effect, use asset versioning — add a hash or version number to the filename.
Full-Page Cache for High-Traffic Sites
If you use WordPress, plugins like WP Rocket or W3 Total Cache generate static HTML versions of your pages. With custom PHP, consider an NGINX FastCGI Cache layer or Varnish in front of Apache.
At elenlace.com we set up hosting environments with properly tuned cache so sites are fast from day one — without clients needing to touch the technical side.
Common Mistakes When Configuring Server Cache
- Caching pages with personalized content: if a URL shows different data per user (cart, profile), it shouldn't be globally cached. Use
Varyheaders or exclude those paths from cache. - TTL too long for frequently changing content: a one-year TTL on files you update without renaming causes visitors to see old versions. Always use asset versioning.
- Forgetting to purge cache after a deploy: if you launch a new version without clearing the cache, visitors see the old version until TTL expires.
- Caching error responses: if the server returns a 500 and cache stores it, all visitors see the error even after the server recovers. Configure your cache engine to skip error status codes.
Key Takeaways
- Server cache stores already-generated responses to avoid repeating expensive PHP and database work.
- There are four main types: Full-Page Cache, Object Cache, OPcache, and HTTP Cache.
- The HIT/MISS cycle determines whether the server delivers a stored copy or generates one fresh.
- OPcache should always be on — it's the easiest, highest-impact PHP performance improvement.
Cache-Controlheaders control what the browser and intermediate proxies store.- Invalidating cache after content changes or deploys is just as important as configuring it.
Want your site to be fast without becoming a server expert? The team at elenlace.com handles all the cache configuration, hosting setup, and performance tuning for you.
FAQ
Is server cache the same as browser cache?
No. Server cache stores responses on the server itself to avoid regenerating them. Browser cache stores static files on the visitor's device to avoid re-downloading them. Both complement each other and operate at different layers.
Can cache show outdated content to visitors?
Yes, if TTL is poorly configured or if cache isn't invalidated after publishing changes. That's why it's essential to set appropriate TTLs per content type and purge the cache whenever you update important information.
Do I need Varnish or Redis to have server cache?
Not necessarily. OPcache is built into PHP and improves performance right away. For full-page caching, NGINX FastCGI Cache or WordPress plugins are more accessible options. Redis and Varnish come into play when traffic volume is high and you need finer control.
Does server cache affect SEO?
Positively. By reducing TTFB and improving Core Web Vitals, it contributes to better Google rankings. Just make sure Googlebot never receives a cached version with errors or blocks that would prevent proper indexing.
Useful resources
Other providers and guides worth comparing: