Twee Object Cache is a suite of high-performance, lightweight object caches built for large-scale WordPress and WooCommerce projects. It provides highly optimized drop-in replacements for the native WordPress in-memory runtime cache, minimizing database load and maximizing execution speed through persistent backend storage.
This repository contains caching plugins for three different backends: APCu, Memcached, and Redis.
- Natively leverages the respective PHP extensions (
apcu,memcached, orredis) for ultra-fast, persistent object caching. - Reduces heavy database queries by reliably maintaining options, transients, and object metadata in memory.
- Safely handles bulk operations (utilizing native methods like
getMultiandsetMultifor Memcached and Redis) to minimize network latency. - For APCu, safely handles memory exhaustion by gracefully deleting keys when storage fails, forcing fresh database reads instead of serving stale data.
- The Memcached implementation automatically splits huge cache payloads into smaller chunks to bypass the server's hard item size limits, completely preventing "Payload too large" errors on massive datasets.
- Implements an internal runtime cache array to prevent redundant backend round-trips during a single page load.
- Automatically trims the runtime cache limit using an efficient, key-preserving slice mechanism to prevent memory exhaustion and array key corruption on massive bulk operations.
- Strictly adheres to functional and procedural paradigms native to WordPress core.
- Fully supports global cache groups for shared data across networks.
- Natively handles non-persistent groups (such as
countsandplugins) by enforcing that they remain exclusively in the runtime cache and never hit the persistent backend. - The Redis implementation natively utilizes Redis Hashes (
hSet,hGet,hDel) to cleanly group cache data, dramatically organizing the global keyspace. - The Memcached implementation manages group isolation using an efficient versioning (namespace) architecture to securely separate keys by their respective cache group.
- Provides full WordPress Multisite support.
- Automatically isolates cache keys using the blog ID prefix to prevent data bleeding across the network.
- Context-aware key prefixing ensures CLI, Cron, and web requests all target the identical caching environment.
Twee Object Cache can be installed as a standard WordPress plugin or as a manual drop-in.
- Switch to PHP 8.0 or a newer version.
- Ensure your preferred caching service (APCu, Memcached, or Redis) is running on your web server and install the corresponding PHP extension.
- Upload the
twee-object-cachefolder to yourwp-content/plugins/directory and activate the plugin via the WordPress dashboard. - Hover over the "Object Cache" menu in the WordPress Admin Bar.
- Select "Enable Redis", "Enable Memcached", or "Enable APCu" based on your environment. The plugin will automatically deploy the correct drop-in, verify connectivity, and start caching.
- Ensure your preferred caching service and PHP extension are installed.
- Manually copy the
object-cache.phpfile from the respective folder (apcu/,memcached/, orredis/) directly into yourwp-content/directory. - WordPress will automatically detect the drop-in and initialize the persistent cache.
All configuration is automatic, but you can explicitly define your cache salt in wp-config.php to guarantee prefix consistency across different execution environments (like WP-CLI).
For Memcached, the following optional constants override connection timeouts. Values are in milliseconds; the defaults are 250 ms:
WP_MEMCACHED_CONNECT_TIMEOUTWP_MEMCACHED_SEND_TIMEOUTWP_MEMCACHED_RECV_TIMEOUT
Author: Andrii Toniievych
Contact: toniyevych@gmail.com
Feel free to contact me if you have any questions.
- Fork this repository
- Commit your changes
- Push it to the branch
- Create the new pull request
Twee is released under the MIT Public License.
Note: The "About" section in README.md and the author (@author) notice in the file-headers shall not be edited or deleted without permission. Thank you!