WordPress / performance

Performance plugin from the WordPress Performance Group, which is a collection of standalone performance modules.
https://wordpress.org/plugins/performance-lab/
GNU General Public License v2.0
350 stars 94 forks source link

Module Proposal: SQLite Persistent Object Cache #625

Open OllieJones opened 1 year ago

OllieJones commented 1 year ago

Overview

About the Module

Purpose

This module persists the WordPress Object Cache using SQLite and php's SQLite3 extension. SQLite3 is enabled on many hosts' php configurations, enabling sites to use persistent object caches even when their hosts do not provision caching servers such as redis or memcached. Persistence is good for site performance: it lightens the load on the MariaDB or MySQL database server and delivers page views and requests to users faster.

Background

WordPress has a well-developed and heavily used Object Cache mechanism, accessible via the WP_Object_Cache class and via functions like wp_cache_set() and wp_cache_get(). Since version 3, WordPress has supported external persistent object caches. To do this, a drop-in module placed in .../wp-content/object-cache.php provides a custom cache implementation. Various plugins, notably Redis Object Cache and Memcached Object Cache, provide persistence via an external redis or memcached server.

Without persistence in its object cache, every WordPress page view and API request must use the MariaDB or MySQL database server to retrieve everything it needs about the site. When a user requests a page, WordPress starts from scratch and gets everything it needs from the database server. Only then can it deliver content to the user. With a persistent object cache, WordPress has much more immediate access to much of the information it needs.

Scope

Operation

If the host php configuration offers the igbinary serializer / deserializer for serializing php variables, this module uses it. That saves a lot of cache space, especially for large and complex cached objects.

If the SQLite3 extension does not exist, or its sqlite has a version prior to 3.7, the module cannot be used, and should not activate.

When activated this module puts its drop-in into .../wp-content/object-cache.php.

These are the drop-in's functions:

These are the functions of the module code managing the drop-in:

Proof of concept

The proposed module is based on the code in the [SQLite Object Cache]() plugin by @OllieJones. The source code to the current version of the plugin's object_cache.php drop-in is here.

OllieJones commented 1 year ago

How well does the proof-of-concept perform? Here are some preliminary results. https://www.plumislandmedia.net/wordpress-plugins/sqlite-object-cache/benchmarks/

If you have a suggestion for how to test performance, please don't hesitate to suggest them, either here or at https://github.com/OllieJones/sqlite-object-cache/issues