Caching explained
![](https://bunny-wp-pullzone-pu34080tue.b-cdn.net/wp-content/uploads/2025/01/AdobeStock_465149021.webp)
Learn all about the different cache types available for PHP, websites, and WordPress in particular.
Zend Opcode, JIT & WP Object Cache
OPcache
OPcache enhances PHP performance by archiving pre-compiled script bytecode in shared memory, which eliminates the need for PHP to load and parse scripts on each request. It also provides a special buffer to store immutable strings so that they can be reused by their pointers for all occurrences of the same string.
Advantage | Major performance improvement. |
---|---|
Activation | Must be enabled in the php.ini configuration file (opcache. enable, opcache. memory_consumption). |
Suggestion | Memory min. 128 MB. String buffer min. 8MB. |
JIT
JIT can bring performance improvements by compiling and storing the full or frequently called parts of a PHP application as CPU machine code, and directly execute it, which bypasses the Zend VM and its process overhead.
Advantage | Performance improvement. |
---|---|
Activation | Must be enabled in the php.ini configuration file (opcode. jit, opcache. jit_buffer_size) and requires Apache to be enabled. |
Suggestion | Enabled with small memory size, 2 MB should be enough. |
Downside | Can cause unpredictable effects. |
WP Object Cache
The WordPress Object Cache is used to save on trips to the database. The Object Cache stores all of the cache data to memory and makes the cache contents available by using a key, which is used to name and later retrieve the cache contents.
The WP Object Cache is a volatile cache, that is only valid for the current request.
Advantage | Is a standard class in WordPress. |
---|---|
Activation | Enabled by default. No configuration. |
Suggestion | Use a persistent object cache to improve performance. |
Persistent Object Cache
Persistent caches store the cached data in a persistent storage so that it can be re-used multiple times without refreshing the original data. It is technically possible to use a database for storage, but memory storage is the only performant option.
Advantage | Major performance improvement for front and back end. |
---|---|
Activation | Each storage option requires it's own extension and the service must be enabled on the server. |
Suggestion | 32M is a good value to start with. Increase it if not enough. |
APCu Cache
APCu (APC User Cache) is a user-level caching solution for PHP that caches data in the server's memory. APCu is the fastest persistent object cache available. It is the only cache that can store objects without serialization.
Redis Cache
Redius is a fast in-memory database using the server's shared memory. If you have multiple WordPress installed in a shared hosting account, all of these installations share the same memory.
Storing non-scalar data in a database requires serialization, which is an extra step when storing/retrieving data. Therefore Redis is slower than APCu but faster than no-cache. Memcached can be accessed via TCP/IP or UNIX socket – which is the faster of the two.
Memcached Cache
Memcached is an in-memory key-value store for small chunks of arbitrary data (strings, objects) from results of database calls, API calls, or page rendering.
Storing non-scalar data in a database requires serialization, which is an extra step when storing/retrieving data. Therefore Memcached is slower than APCu but faster than no-cache. Redis can be accessed via TCP/IP or UNIX socket – which is the faster of the two.
Browser Cache & Content Delivery Networks (CDN)
Browser Cache
To shorten page load times, browsers cache most of the content that appears on a web page, saving a copy of the web page's content on the device's hard drive. This way, the next time the user loads the page, most of the content is already stored locally and the page will load much more quickly.
Advantage | Saving load time and bandwidth. |
---|---|
Activation | Browser caching is enabled by default, but can be improved by cache directives on the server. The settings can either be set in the web-server configuration or in the .htaccess file (Apache web-server). |
Suggestion | Set the Cache-Control header with the a high max-age value. |
CDN
A content delivery network (CDN) is a distributed group of servers that caches content near end users.
Advantage | Reduces the load on a server and improves the response time to the client. |
---|---|
Activation | Requires a subscription with a CDN-provider such as cloudflare or bunny.net. |
Suggestion | A CDN is not required for small static sites with a local user base, but can drastically improve load times for a global user base, as the CDN provides lower latency for every request. |