CacheerPHP CacheerPHP
GitHub

CacheerPHP

Fast, minimalist and flexible PHP caching library — with multiple drivers (files, database, Redis), human-friendly TTLs, optional compression/encryption, and a fluent OptionBuilder.

Installation

composer require silviooosilva/cacheer-php

Highlights

  • Multiple drivers: Array, Files, Database, Redis
  • Readable TTLs: seconds, minutes, hours
  • Optional compression and encryption
  • Static and instance APIs

Minimal and Fast

Lightweight core with zero runtime dependencies for the common path.

Pluggable Drivers

File, Database, Redis and Array — swap backends without changing your code.

Compression & Encryption

Optional gzip compression and AES‑256 encryption for secure and smaller payloads.

Fluent Builders

Configure options with fluent builders and time helpers for error‑free setup.

Tagging

Group keys and invalidate them in bulk across supported drivers.

Static or Instance API

Use convenient static helpers or work with an instance for full control.

Why developers choose CacheerPHP?

Secure, fluent and flexible — from file cache to Redis, with human-time TTLs, tags, and optional compression + encryption.

Encrypted + Compressed API cache (tagged)

Cache heavy API responses on disk, compress to save space, encrypt to protect data, and tag to clear related entries at once.

<?php
require __DIR__ . '/vendor/autoload.php';

use Silviooosilva\\CacheerPhp\\Cacheer;
use Silviooosilva\\CacheerPhp\\Core\\OptionBuilder;

$opts = OptionBuilder::forFile()
    ->dir(__DIR__ . '/.cache')      // storage dir
    ->expirationTime('30 minutes')  // default TTL when omitted
    ->flushAfter('1 day')           // daily auto-flush check
    ->build();

$cache = new Cacheer($opts);
$cache->setDriver()->useFileDriver();
$cache->useCompression()->useEncryption(getenv('APP_KEY') ?: 'dev-key');

$url = 'https://api.github.com/users?since=1000';
$key = 'http:gh:users:since-1000';

$data = $cache->getCache($key);
if (!$cache->has($key)) {
    $json = file_get_contents($url);
    $data = json_decode($json, true);
    $cache->putCache($key, $data);   // uses default TTL (30m)
    $cache->tag('github-users', $key);
}

// Later: clear all related entries
//$cache->flushTag('github-users');

Redis with namespaces, defaults and tag flush

Define defaults once with OptionBuilder, override TTLs per item, organize with namespaces, and invalidate via tags.

<?php
require __DIR__ . '/vendor/autoload.php';

use Silviooosilva\\CacheerPhp\\Cacheer;
use Silviooosilva\\CacheerPhp\\Core\\OptionBuilder;

$opts = OptionBuilder::forRedis()
    ->setNamespace('app:')       // prefix for keys
    ->expirationTime('2 hours')  // default TTL when omitted or 3600
    ->flushAfter('1 day')        // auto-flush check
    ->build();

$cache = new Cacheer($opts);
$cache->setDriver()->useRedisDriver();

// Uses explicit TTL (overrides default)
$cache->putCache('profile', ['id' => 123], 'nsA', '10 minutes');
$cache->putCache('settings', ['dark' => true], 'nsA'); // defaults to 2h

$cache->tag('users', 'nsA:profile', 'nsA:settings');

// Bulk invalidation by tag
//$cache->flushTag('users');
ALL ABOUT CACHEERPHP

Frequently asked questions

Get quick answers to the most common questions about CacheerPHP.

Is CacheerPHP free?

Yes. CacheerPHP is open‑source and free to use in commercial projects. Documentation, examples and community support are also freely available.

Who maintains CacheerPHP?

CacheerPHP is actively maintained by contributors focused on performance and simplicity. Pull requests and feedback are welcome on GitHub.

How does it differ from basic caching?

Fluent defaults and safety. OptionBuilder eliminates typo‑prone arrays, human‑time TTLs reduce mistakes, and features like tags, compression and encryption are first‑class.

Do I need to rewrite existing code?

No. Start small using static helpers, or adopt step‑by‑step with instances and drivers. Migrate keys gradually; tags help invalidate old groups safely.

What PHP versions are supported?

PHP 8.0+. For security and performance we recommend PHP 8.2 or newer.

How do I pick a driver?

Local apps: Files. High‑throughput/multi‑node: Redis. DB‑centric: Database. For tests or short‑lived data: Array. Switch with setDriver() at any time.