tuki / vapordb
Requires
- php: ^8.3
- ext-memcached: *
Requires (Dev)
- brain/monkey: ^2.7
- mockery/mockery: ^1.6
- phpstan/extension-installer: ^1.4
- phpstan/phpstan: ^2.1
- phpunit/phpunit: ^12.5
- squizlabs/php_codesniffer: ^4.0
- szepeviktor/phpstan-wordpress: ^2.0
This package is auto-updated.
Last update: 2026-03-17 15:36:37 UTC
README
A lightweight WordPress plugin that accelerates database-heavy queries by short-circuiting the most common post lookups and metadata fetches into Memcached. VaporDB registers a small set of hooks (posts_pre_query, found_posts, get_post_metadata, save_post) and uses a pluggable cache adapter so you can swap in any CacheInterface implementation.
Features
- Transparent caching for WP_Query results and
get_post_metadatacalls - Automatic invalidation on
save_post - Configurable cache backend via a single filter
- Sensible defaults (prefix
vapordb:, 1h TTL) and graceful error logging viaVaporErrorException
Requirements
- PHP 8.3+
- WordPress 6.0+ (hooks-based integration)
- Memcached PHP extension and a running Memcached server (or your own
CacheInterfaceadapter)
Installation
With Composer (recommended)
composer require tuki/vapordb
Then ensure the plugin directory is present in wp-content/plugins/vapordb (or load it via a must-use plugin) and activate VaporDB in the WordPress admin. Composer’s autoloader is used when available; otherwise a simple PSR-4 fallback in vapordb.php is used.
Manual plugin drop-in
1) Copy this repository into wp-content/plugins/vapordb.
2) Run composer install inside the plugin folder to pull dependencies.
3) Activate “VaporDB” from the WordPress Plugins screen.
Configuration
By default VaporDB instantiates a Memcached client with the default constructor. To customize the cache backend, provide a CacheInterface via the vapordb_cache_adapter filter:
add_filter('vapordb_cache_adapter', function () {
$client = new Memcached();
$client->addServer('127.0.0.1', 11211);
// Prefix keys and set a shorter TTL (e.g., 10 minutes)
return new \Tuki\VaporDB\Core\Cache($client, 'vapordb:', 600);
});
Any adapter implementing Tuki\VaporDB\Contracts\CacheInterface will work (Redis, in-memory, etc.).
How it works
posts_pre_query: returns cached posts for a givenWP_Querybefore hitting the DB.found_posts: caches the total found posts count for paginated queries.get_post_metadata: serves metadata from cache when available.save_post: invalidates cached entries related to the saved post. Errors are wrapped inVaporErrorExceptionand logged whenWP_DEBUGis enabled; an admin notice is optionally shown whenWP_DEBUG_DISPLAYis on.
Usage examples
- Cache a custom query result manually by seeding the cache:
$query_vars = ['post_type' => 'book', 'posts_per_page' => 5]; ksort($query_vars); $key = md5(serialize($query_vars)) . \Tuki\VaporDB\Hooks\PostPreQueryHook::CACHE_KEY_SUFFIX;
$cache = new \Tuki\VaporDB\Core\Cache((new Memcached())); $cache->set($key, $pre_fetched_posts, 900); // 15-minute TTL
- Provide a no-op cache during local development:
use Tuki\VaporDB\Contracts\CacheInterface;
class NullCache implements CacheInterface {
public function get(string $key): mixed { return null; }
public function set(string $key, mixed $value, int $ttl = 3600): bool { return true; }
public function delete(string $key): bool { return true; }
public function has(string $key): bool { return false; }
}
add_filter('vapordb_cache_adapter', fn () => new NullCache());
## Development
- Install deps: `composer install`
- Run unit tests: `composer unit-tests`
- Run static analysis: `composer phpstan-analyze`
- Check coding style: `composer check-style`
## License
MIT License. See `LICENSE` for details.