What is a cache?
Any fast storage placed in front of slower storage to hold recently or frequently used data. The idea repeats at every layer of a computer. CPU caches hide the slowness of RAM. RAM caches hide the slowness of disks. Application caches hide the cost of database queries and page rendering. HTTP caches hide the distance to the origin server. Each layer works the same way: check the fast copy first (a hit), and fall back to the slow source only when needed (a miss).
What are the layers of caching on a server?
| Layer | Typical size | Access time | Managed by |
|---|---|---|---|
| CPU L1 / L2 | Tens of KB to a few MB per core | About 1 to 5 ns | Hardware |
| CPU L3 | Tens to hundreds of MB per chip | About 10 to 20 ns | Hardware |
| RAM page cache | All free memory | About 100 ns | Linux kernel |
| Database buffer pool | Configured share of RAM | Sub-microsecond | MySQL, PostgreSQL |
| Application and object cache | MB to many GB | Microseconds | OPcache, Redis, Memcached |
| HTTP cache | GB on RAM or NVMe | Microseconds plus network | nginx, Varnish, CDNs |
The memory hierarchy explains the hardware side of this ladder in more depth.
Where did all the free RAM go?
Because the page cache uses it. Linux keeps recently read file data in otherwise unused RAM, so the second read of a file comes from memory. That memory is handed back instantly when programs need it. The number to watch is available, not free:
free -h grep -E '^(Cached|Buffers|MemAvailable)' /proc/meminfo
A server with plenty of available memory and high cache use is healthy. This is also why extra RAM speeds up file servers and databases even when no program asks for it directly. Check memory usage walks through the output.
How do CPU caches affect performance?
Code and data that fit in L1 and L2 run at full speed; every miss to RAM costs hundreds of cycles. Large L3 caches help databases, game servers and virtual machines that jump around in memory. CPU families differ widely here: the EPYC 4005 chips in S13 and S14 and the Xeon 6 chips in our Xeon 6 line line carry large L3 caches. Check yours with lscpu | grep -i cache. Software can help too: compact data structures and processing data in order make better use of whatever cache the CPU has.
Which application caches should a web server use?
- Bytecode cache: PHP OPcache keeps compiled scripts in memory. Turn it on everywhere; it often doubles PHP throughput on its own.
- Object cache: Redis or Memcached holds query results, sessions and computed fragments; In-memory caches and stores covers sizing.
- Full-page cache: nginx
fastcgi_cacheorproxy_cachestores rendered pages for anonymous visitors, turning a 100 ms page into a sub-millisecond one. - Browser cache: long
Cache-Controllifetimes on versioned static files keep repeat visitors from downloading them again, which also saves outgoing traffic.
What makes caching hard?
Invalidation: knowing when a cached copy is out of date. Short lifetimes are simple but cache less; long lifetimes need a way to purge or version entries when data changes. The other trap is caching personal data and serving it to the wrong user, so exclude logged-in sessions and anything with cookies from shared caches unless you know exactly what you are doing. Measure the hit ratio at each layer: redis-cli info stats shows keyspace hits and misses, and nginx can log $upstream_cache_status.
How does cache shape hardware choices?
When a workload's hot data fits in RAM, it runs at memory speed; when it spills over, it runs at disk speed. That makes RAM the most effective upgrade for many databases and caches. Our High memory line line goes from 512 GB DDR4 on M1 to 1 TB DDR5 on M13. A dedicated Cache server takes the idea further by putting a whole machine in front of the slow source.
Machines With Large Caches and RAM
| Server | Processor | Cores / threads | Memory | Storage | Network | Per month | Smallest order |
|---|---|---|---|---|---|---|---|
| S5 | Intel Xeon E-2276G | 6 / 12 | 128 GB DDR4 | 2x 1 TB NVMe | 2x 10 Gbps | $88.72 | $88.72 (1 month) |
| S13 | AMD EPYC 4345P | 8 / 16 | 128 GB DDR5 | 2x 2 TB NVMe | 2x 25 Gbps | $237.92 | $237.92 (1 month) |
| S14 | AMD EPYC 4565P | 16 / 32 | 192 GB DDR5 | 2x 4 TB NVMe | 2x 25 Gbps | $317.89 | $317.89 (1 month) |
| M1 | 2x Intel Xeon Gold 5315Y | 16 / 32 | 512 GB DDR4 | 2x 4 TB NVMe | 2x 25 Gbps | $414.70 | $414.70 (1 month) |
| M13 | 2x Intel Xeon Gold 5418Y | 48 / 96 | 1 TB DDR5 | 2x 4 TB NVMe | 2x 25 Gbps | $849.12 | $849.12 (1 month) |
Keep Reading
Cache server
A server that keeps copies of frequently requested data close to users or apps so the slow origin is asked less often.
OpenThe memory hierarchy
From registers through L1, L2 and L3 caches to RAM, NVMe and the network: how each level trades speed for size, and why it shapes performance.
OpenIn-memory caches and stores
Redis, Valkey or Memcached on machines with 128 GB to 1 TB of RAM, sized with snapshot headroom and NUMA in mind.
OpenCheck memory usage
Read free, /proc/meminfo, vmstat and per-process numbers correctly, and tell real memory pressure apart from a healthy page cache.
OpenFAQ
Quick Answers
A request answered from the cache. A miss is one that has to go to the slower original source.
Linux uses free RAM as page cache for files. Check the available column in free -h, which counts memory that can be reclaimed.
They are CPU caches of growing size and latency. L1 and L2 are per core, L3 is shared across the chip.
Yes. It stores compiled scripts in memory and is one of the cheapest speedups for any PHP site.
When the working data does not fit in memory, yes. More of it stays in the page cache or database buffers instead of on disk.