Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

28 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Twee Object Cache

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.

Features

1. High-Performance Integration

  • Natively leverages the respective PHP extensions (apcu, memcached, or redis) 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 getMulti and setMulti for 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.

2. Dual-Layer Caching Engine

  • 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.

3. Advanced Group Management

  • Fully supports global cache groups for shared data across networks.
  • Natively handles non-persistent groups (such as counts and plugins) 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.

4. Multisite & Context Compatibility

  • 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.

Installation

Twee Object Cache can be installed as a standard WordPress plugin or as a manual drop-in.

1. WordPress Plugin Installation (Recommended)

  • 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-cache folder to your wp-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.

2. Manual Drop-in Installation

  • Ensure your preferred caching service and PHP extension are installed.
  • Manually copy the object-cache.php file from the respective folder (apcu/, memcached/, or redis/) directly into your wp-content/ directory.
  • WordPress will automatically detect the drop-in and initialize the persistent cache.

Configuration

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_TIMEOUT
  • WP_MEMCACHED_SEND_TIMEOUT
  • WP_MEMCACHED_RECV_TIMEOUT

About

Author: Andrii Toniievych

Contact: toniyevych@gmail.com

Feel free to contact me if you have any questions.

Contribution

  • Fork this repository
  • Commit your changes
  • Push it to the branch
  • Create the new pull request

License

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!

About

A suite of lightweight, highly optimized APCu, Memcached, and Redis object caches for large-scale WordPress and WooCommerce projects.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages