tuki/vapordb

Maintainers

Package info

gitlab.com/Grupotuki/vapordb

Issues

pkg:composer/tuki/vapordb

Statistics

Installs: 3

Dependents: 0

Suggesters: 0

Stars: 0

v1.0.1 2026-03-17 16:34 UTC

This package is auto-updated.

Last update: 2026-03-17 15:36:37 UTC


README

PHP Pipeline Status Downloads Latest Version

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_metadata calls
  • Automatic invalidation on save_post
  • Configurable cache backend via a single filter
  • Sensible defaults (prefix vapordb:, 1h TTL) and graceful error logging via VaporErrorException

Requirements

  • PHP 8.3+
  • WordPress 6.0+ (hooks-based integration)
  • Memcached PHP extension and a running Memcached server (or your own CacheInterface adapter)

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 given WP_Query before 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 in VaporErrorException and logged when WP_DEBUG is enabled; an admin notice is optionally shown when WP_DEBUG_DISPLAY is 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.