=== WP LCache === Contributors: getpantheon, danielbachhuber, stevector Tags: apc, apcu, cache, caching, lcache, object-cache, performance Requires at least: 4.3 Tested up to: 5.2 Stable tag: 0.6.1 License: GPL-2.0 License URI: https://www.gnu.org/licenses/gpl-2.0.html Supercharge your WP Object Cache with LCache, a persistent, performant, and multi-layer cache library. == Description == For sites concerned with high traffic, speed for logged-in users, or dynamic pageloads, a high-speed and persistent object cache is a must. WP LCache improves upon Memcached and Redis object cache implementations by using APCu, PHP's in-memory cache, in a way that's compatible with multiple web nodes. Under the hood, WP LCache uses [LCache](https://github.com/lcache/lcache), a library that applies the tiered caching model of multi-core processors (with local L1 and central L2 caches) to web applications. **Note**: WP LCache development is currently on hold, and not recommendated for production use, due to an [issue with APCu cache fragmentation](https://github.com/lcache/wp-lcache/issues/138). [WP Redis](https://wordpress.org/plugins/wp-redis/), also maintained by Pantheon, is a great alternative. WP LCache is faster than other object cache implementations because: * By using APCu, which is in-memory, WP LCache uses the fastest possible persistent object cache backend and avoids costly network connections on every request. When using a Memcached or Redis-based persistent object cache where Memcached or Redis is on a different machine, the millisecond cost of each cache hit can add up to seconds of network transactions on every request. * By incorporating a common L2 cache, WP LCache synchronizes cache data between multiple web nodes. Cache updates or deletes on one node are then applied to all other nodes. Without this synchronization behavior, APCu can't be used in server configurations with multiple web nodes because the cache pool is local to the machine. Still not convinced? WP LCache includes features that no one else has: * Cache groups are handled natively, meaning you can delete an entire group of keys with `wp_cache_delete_group()`. * WordPress' alloptions cache is sharded into distinct keys, mitigating cache pollution on high traffic sites. [Read #31245](https://core.trac.wordpress.org/ticket/31245) for all of the gory details. Read the installation instructions, then install WP LCache from [WordPress.org](https://wordpress.org/plugins/wp-lcache/) or [Github](https://github.com/lcache/wp-lcache). Go forth and make awesome! And, once you've built something great, [send us feature requests (or bug reports)](https://github.com/lcache/wp-lcache/issues). == Frequently Asked Questions == = Do you have benchmarks you can share? = We've done some rudimentary testing with New Relic on Pantheon infrastructure. [The results](https://twitter.com/outlandishjosh/status/775756511611990016) were substantial enough for us to begin using LCache in production. [Watch David Strauss' DrupalCon presentation](https://twitter.com/outlandishjosh/status/781281995213115396) for a more thorough explanation. If you'd like to do some benchmarking yourself, we'd love to hear about your testing methodology and conclusions. Caching is more of an art than a science, and outcomes can vary. Because cost of network transactions is one of the problems solved by WP LCache, the performance gains will be more impressive if you've historically been using Redis or Memcached on a separate machine. = Is APCu persistent like Redis is? = APCu is persistent through the life of a PHP-FPM process. However, unlike Redis, APCu doesn't save its state to disk at shutdown. When PHP-FPM is restarted, WP LCache will repopulate the L1 cache (APCu) from the L2 cache (database). = Why am I seeing heavy database load from WP LCache? = When you first enable WP LCache, you'll have a good amount of database activity as it writes all cache entries to the database. Eventually, as long as your codebase is optimized, database activity will die down and most activity will be in APCu. However, if your codebase isn't optimized, you'll see continued database load. Some common issues include: * Frequent calls to `wp_cache_flush()`, which empties the entire cache and requires the L2 to be completely repopulated. * Redundant or duplicative calls to `wp_cache_set()`, where code paths hardly ever use the cache values they set. In both of these cases, any persistent object cache drop-in probably isn't going to be useful until you solve your code problems. == Installation == **WP LCache requires PHP 5.6 or greater with the APCu extension enabled.** To install WP LCache, follow these steps: 1. Install the plugin from WordPress.org using the WordPress dashboard. 1a. Those installing from Github will need to run `composer install --no-dev --no-scripts` after cloning to get the [LCache library](https://github.com/lcache/lcache). 2. Activate the plugin, to ensure LCache's database tables are created. These are created on the plugin activation hook. 3. Create a stub file at `wp-content/object-cache.php` to require `wp-content/plugins/wp-lcache/object-cache.php`. The `wp-content/object-cache.php` file should contain: