EffortLess Opcode and Object Cache
WordPress Site Health reports two performance items: “Opcode cache is not enabled” and “You should use a persistent object cache”. This plugin reports the state of both and, where the server allows it, changes it. OPcache keeps compiled PHP code in memory. It is a setting of the PHP installation, so
WordPress Site Health reports two performance items: “Opcode cache is not enabled” and “You should use a persistent object cache”. This plugin reports the state of both and, where the server allows it, changes it.
OPcache keeps compiled PHP code in memory. It is a setting of the PHP installation, so a plugin cannot install it. The plugin shows whether the extension is loaded, whether opcache.enable is on, the main OPcache settings and, when enabled, memory use, number of cached scripts and hit rate. If the extension is loaded but switched off and PHP runs as CGI or FastCGI/FPM, the plugin can add opcache.enable=0 to the .user.ini file in the WordPress folder, between marker lines, leaving other content of that file as it is. PHP does not allow a .user.ini file to switch OPcache on after the server started with it off, so the plugin shows the lines to put in php.ini or the host’s PHP settings instead.
Persistent object cache. WordPress core caches database results only during one request. With a drop-in file, wp-content/object-cache.php , the results are stored in Redis, Memcached, APCu or in files, and reused by later requests. The plugin writes that file from a template with your settings, and removes it again on request or when the plugin is deactivated. The drop-in implements the WordPress cache functions, including wp_cache_get_multiple() , wp_cache_flush_group() and the other multiple-key functions.
How the cache behaves:
- Entries are stored under a key made of a random per-installation salt, a version token, the group, the site ID (except for global groups) and the key.
- Flushing the whole cache or one group changes a version token. Nothing is scanned or deleted on the server; old entries are no longer read and expire.
- Entries saved without an expiry get a maximum age (default 7 days), so old data does not stay on the server for ever.
- Non-persistent groups registered by WordPress stay in memory for the request only.
- If the server cannot be reached, or the PHP extension is missing, the cache keeps working for the current request only. The status page then shows the error.
- incr and decr read, change and write the value; they are not atomic between simultaneous requests.