WP LCache | Pantheon, Daniel Bachhuber

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, 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. 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 for all of the gory details.

Read the installation instructions, then install WP LCache from WordPress.org or Github.

Go forth and make awesome! And, once you’ve built something great, send us feature requests (or bug reports).

Contributing

The best way to contribute to the development of this plugin is by participating on the GitHub project:

https://github.com/lcache/wp-lcache

Pull requests and issues are welcome!

You may notice there are two sets of tests running, on two different services:

  • Travis CI runs the PHPUnit test suite in a variety of environment configurations (e.g. APCu available vs. APCu unavailable).
  • Circle CI runs the Behat test suite against a Pantheon site, to ensure the plugin’s compatibility with the Pantheon platform.

Both of these test suites can be run locally, with a varying amount of setup.

PHPUnit requires the WordPress PHPUnit test suite, and access to a database with name wordpress_test. If you haven’t already configured the test suite locally, you can run bash bin/install-wp-tests.sh wordpress_test root '' localhost. You’ll also need to install and configure APCu in order to run the test suite against APCu.

Behat requires a Pantheon site. Once you’ve created the site, you’ll need install Terminus, and set the TERMINUS_TOKEN, TERMINUS_SITE, and TERMINUS_ENV environment variables. Then, you can run ./bin/behat-prepare.sh to prepare the site for the test suite.

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

<?php
# Engage LCache object caching system.
# We use a 'require_once()' here because in PHP 5.5+ changes to symlinks
# are not detected by the opcode cache, making it frustrating to deploy.
#
# More info: http://codinghobo.com/opcache-and-symlink-based-deployments/
#
$lcache_path = dirname( realpath( __FILE__ ) ) . '/plugins/wp-lcache/object-cache.php';
require_once( $lcache_path );

To install WP LCache in one line with WP-CLI:

wp plugin install wp-lcache – activate && wp lcache enable

If you need to install APCu, the PECL installer is the easiest way to do so.

  • PHP 7.0: pecl install apcu
  • PHP 5.6: pecl install channel://pecl.php.net/apcu-4.0.11

Enabling APCu for CLI is a matter of adding apc.enable_cli='on' to your etc/php5/cli/php.ini.

If you can’t easily use PHP 5.6 or greater, you should switch to a more responsible hosting provider.

Admin Notices

If any of the requirements for LCache to function are not met, you will see an admin notice indicating the issue. Here’s how to resolve issues for each possible dependency:

  • “LCache database table”: This indicates you have the object-cache.php symlink in place, but have not activated the plugin (which installs the LCache db table). Activate the plugin and verify the LCache tables are created.
  • “PHP 5.6 or greater”: You need to update your PHP runtime, which will also make your site faster and more secure. Do it today, or contact your hosting provider if you don’t have access.
  • “APCu extension installed/enabled”: You don’t have the required PHP extension to power LCache. See above instructions for installing APCU, or contact your hosting provider.
  • “LCache library”: you’re probably installing direct from GitHub, not a download from the WordPress.org plugins directory. Awesome! You just need to run composer install – no-dev inside the wp-lcache directory, and make sure the resulting vendor directory is deployed along with the rest of wp-lcache.

Plugin author

Pantheon, Daniel Bachhuber

Plugin official website address

https://wordpress.org/plugins/wp-lcache/
If you encounter problems in using the WP LCache plugin, you can comment below, and I will try my best to help you solve the problem

Leave a Comment

Your email address will not be published.

WP LCache | Pantheon, Daniel Bachhuber

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, 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. 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 for all of the gory details.

Read the installation instructions, then install WP LCache from WordPress.org or Github.

Go forth and make awesome! And, once you’ve built something great, send us feature requests (or bug reports).

Contributing

The best way to contribute to the development of this plugin is by participating on the GitHub project:

https://github.com/lcache/wp-lcache

Pull requests and issues are welcome!

You may notice there are two sets of tests running, on two different services:

  • Travis CI runs the PHPUnit test suite in a variety of environment configurations (e.g. APCu available vs. APCu unavailable).
  • Circle CI runs the Behat test suite against a Pantheon site, to ensure the plugin’s compatibility with the Pantheon platform.

Both of these test suites can be run locally, with a varying amount of setup.

PHPUnit requires the WordPress PHPUnit test suite, and access to a database with name wordpress_test. If you haven’t already configured the test suite locally, you can run bash bin/install-wp-tests.sh wordpress_test root '' localhost. You’ll also need to install and configure APCu in order to run the test suite against APCu.

Behat requires a Pantheon site. Once you’ve created the site, you’ll need install Terminus, and set the TERMINUS_TOKEN, TERMINUS_SITE, and TERMINUS_ENV environment variables. Then, you can run ./bin/behat-prepare.sh to prepare the site for the test suite.

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

<?php
# Engage LCache object caching system.
# We use a 'require_once()' here because in PHP 5.5+ changes to symlinks
# are not detected by the opcode cache, making it frustrating to deploy.
#
# More info: http://codinghobo.com/opcache-and-symlink-based-deployments/
#
$lcache_path = dirname( realpath( __FILE__ ) ) . '/plugins/wp-lcache/object-cache.php';
require_once( $lcache_path );

To install WP LCache in one line with WP-CLI:

wp plugin install wp-lcache – activate && wp lcache enable

If you need to install APCu, the PECL installer is the easiest way to do so.

  • PHP 7.0: pecl install apcu
  • PHP 5.6: pecl install channel://pecl.php.net/apcu-4.0.11

Enabling APCu for CLI is a matter of adding apc.enable_cli='on' to your etc/php5/cli/php.ini.

If you can’t easily use PHP 5.6 or greater, you should switch to a more responsible hosting provider.

Admin Notices

If any of the requirements for LCache to function are not met, you will see an admin notice indicating the issue. Here’s how to resolve issues for each possible dependency:

  • “LCache database table”: This indicates you have the object-cache.php symlink in place, but have not activated the plugin (which installs the LCache db table). Activate the plugin and verify the LCache tables are created.
  • “PHP 5.6 or greater”: You need to update your PHP runtime, which will also make your site faster and more secure. Do it today, or contact your hosting provider if you don’t have access.
  • “APCu extension installed/enabled”: You don’t have the required PHP extension to power LCache. See above instructions for installing APCU, or contact your hosting provider.
  • “LCache library”: you’re probably installing direct from GitHub, not a download from the WordPress.org plugins directory. Awesome! You just need to run composer install – no-dev inside the wp-lcache directory, and make sure the resulting vendor directory is deployed along with the rest of wp-lcache.

Plugin author

Pantheon, Daniel Bachhuber

Plugin official website address

https://wordpress.org/plugins/wp-lcache/
If you encounter problems in using the WP LCache plugin, you can comment below, and I will try my best to help you solve the problem

Leave a Comment

Your email address will not be published.