PHPackages                             silviooosilva/cacheer-php - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Database &amp; ORM](/categories/database)
4. /
5. silviooosilva/cacheer-php

ActiveLibrary[Database &amp; ORM](/categories/database)

silviooosilva/cacheer-php
=========================

CacheerPHP is a minimalist package for caching in PHP, offering a simple interface for storing and retrieving cached data using multiple backends.

5.1.0(1mo ago)3210631MITPHPPHP &gt;=8.2

Since Jul 18Pushed 5d ago1 watchersCompare

[ Source](https://github.com/CacheerPHP/CacheerPHP)[ Packagist](https://packagist.org/packages/silviooosilva/cacheer-php)[ Docs](https://github.com/silviooosilva)[ RSS](/packages/silviooosilva-cacheer-php/feed)WikiDiscussions main Synced today

READMEChangelog (10)Dependencies (12)Versions (62)Used By (1)

CacheerPHP
==========

[](#cacheerphp)

 [![CacheerPHP Logo](./art/cacheer_php_logo__.png)](https://github.com/silviooosilva/CacheerPHP)

 **A modern, fluent PHP caching library with multiple backends, PSR compliance, encryption and zero framework dependencies.**

 [![Latest Version](https://camo.githubusercontent.com/1c8b47012d6200e83eb67467510184f811478746bbb33969199d5dadcbe524b4/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f72656c656173652f73696c76696f6f6f73696c76612f436163686565725048502e7376673f7374796c653d666f722d7468652d626164676526636f6c6f723d626c7565)](https://github.com/silviooosilva/CacheerPHP/releases) [![PHP Version](https://camo.githubusercontent.com/a71c6079c918992d8875763645200af37f6511374f0e354f234bbedead0e2afe/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f646570656e64656e63792d762f73696c76696f6f6f73696c76612f636163686565722d7068702f5048503f7374796c653d666f722d7468652d626164676526636f6c6f723d626c7565)](https://camo.githubusercontent.com/a71c6079c918992d8875763645200af37f6511374f0e354f234bbedead0e2afe/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f646570656e64656e63792d762f73696c76696f6f6f73696c76612f636163686565722d7068702f5048503f7374796c653d666f722d7468652d626164676526636f6c6f723d626c7565) [![Downloads](https://camo.githubusercontent.com/3ae20a2734a99917d110bb3ac62f7ef815ec7ba15c82410cb81be494037c058a/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f73696c76696f6f6f73696c76612f636163686565722d7068703f7374796c653d666f722d7468652d626164676526636f6c6f723d626c7565)](https://camo.githubusercontent.com/3ae20a2734a99917d110bb3ac62f7ef815ec7ba15c82410cb81be494037c058a/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f73696c76696f6f6f73696c76612f636163686565722d7068703f7374796c653d666f722d7468652d626164676526636f6c6f723d626c7565) [![Quality Score](https://camo.githubusercontent.com/184f676339ba6e74d370dcb89c20d7f9a16ae9797c56b2724f0d0858db44b9c5/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f73696c76696f6f6f73696c76612f436163686565725048502e7376673f7374796c653d666f722d7468652d626164676526636f6c6f723d626c7565)](https://scrutinizer-ci.com/g/silviooosilva/CacheerPHP) [![Maintainer](https://camo.githubusercontent.com/3a24f7f9521210d6e5784931e9c55dc1d66d889e8ff828ecd51eed01444d668f/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6d61696e7461696e65722d4073696c76696f6f6f73696c76612d626c75652e7376673f7374796c653d666f722d7468652d626164676526636f6c6f723d626c7565)](https://github.com/silviooosilva/CacheerPHP)

---

Why CacheerPHP?
---------------

[](#why-cacheerphp)

Most PHP caching solutions are either too minimal or buried inside a framework. CacheerPHP gives you a **complete caching toolkit** that works anywhere — from a small script to a full application — with a clean, fluent API and no framework lock-in.

- **4 storage drivers** — File, Database (MySQL/PostgreSQL/SQLite), Redis and in-memory Array
- **PSR-16 &amp; PSR-3** — Standards-compliant SimpleCache adapter and logger out of the box
- **AES-256-CBC encryption** — Protect sensitive cached data with a single method call
- **Gzip compression** — Reduce storage footprint automatically
- **Fluent OptionBuilder** — Type-safe, IDE-friendly configuration with zero typos
- **Tags &amp; namespaces** — Group and invalidate related entries effortlessly
- **Human-readable TTL** — Write `"2 hours"` instead of `7200`
- **Static &amp; instance API** — Use whichever style fits your codebase
- **150+ tests** — Battle-tested with PHPUnit

---

Quick Start
-----------

[](#quick-start)

```
composer require silviooosilva/cacheer-php
```

```
use Silviooosilva\CacheerPhp\Cacheer;

$cache = new Cacheer(['cacheDir' => __DIR__ . '/cache']);
$cache->setDriver()->useFileDriver();

// Write
$cache->putCache('user:1', ['id' => 1, 'name' => 'John']);

// Read
$user = $cache->getCache('user:1');

// Check
if ($cache->has('user:1')) {
    echo "Cache hit!";
}
```

That's it — you're caching. Keep reading for the good stuff.

---

Table of Contents
-----------------

[](#table-of-contents)

- [Drivers](#drivers)
- [Configuration](#configuration)
- [OptionBuilder](#optionbuilder)
- [Encryption &amp; Compression](#encryption--compression)
- [Tags &amp; Namespaces](#tags--namespaces)
- [PSR-16 SimpleCache](#psr-16-simplecache)
- [Formatter](#formatter)
- [API Reference](#api-reference)
- [Testing](#testing)
- [Documentation](#documentation)
- [Contributing](#contributing)
- [License](#license)

---

Drivers
-------

[](#drivers)

Switch between backends with a single call:

```
$cache->setDriver()->useFileDriver();      // Filesystem
$cache->setDriver()->useDatabaseDriver();  // MySQL, PostgreSQL, SQLite
$cache->setDriver()->useRedisDriver();     // Redis
$cache->setDriver()->useArrayDriver();     // In-memory (great for tests)
```

FeatureFileDatabaseRedisArrayPersistenceDiskDBServerNoTagsYesYesYesYesNamespacesYesYesYesYesCompressionYesYesYesYesEncryptionYesYesYesYesAuto-flushYesYesYes-Best forSingle serverShared stateHigh throughputTesting---

Configuration
-------------

[](#configuration)

### Environment variables

[](#environment-variables)

Copy the example file and adjust:

```
cp .env.example .env
```

```
# SQLite (default)
DB_CONNECTION=sqlite

# MySQL / PostgreSQL
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=cacheer_db
DB_USERNAME=root
DB_PASSWORD=secret

# Redis
REDIS_HOST=127.0.0.1
REDIS_PORT=6379
```

### Plain array

[](#plain-array)

```
$cache = new Cacheer([
    'cacheDir'       => __DIR__ . '/cache',
    'loggerPath'     => __DIR__ . '/logs/cacheer.log',
    'expirationTime' => '1 hour',
    'flushAfter'     => '1 day',
]);
```

### Static API

[](#static-api)

```
Cacheer::setConfig()->setTimeZone('UTC');
Cacheer::setDriver()->useArrayDriver();

Cacheer::putCache('key', 'value');
$value = Cacheer::getCache('key');
```

---

OptionBuilder
-------------

[](#optionbuilder)

Forget string typos. The `OptionBuilder` gives you a **fluent, type-safe** way to configure each driver with full IDE autocompletion:

```
use Silviooosilva\CacheerPhp\Config\Option\Builder\OptionBuilder;

$options = OptionBuilder::forFile()
    ->dir(__DIR__ . '/cache')
    ->loggerPath(__DIR__ . '/logs/cache.log')
    ->expirationTime('2 hours')
    ->flushAfter('1 day')
    ->build();

$cache = new Cacheer($options);
$cache->setDriver()->useFileDriver();
```

Each driver has its own builder with driver-specific methods:

```
// Redis
$options = OptionBuilder::forRedis()
    ->setNamespace('app:')
    ->loggerPath(__DIR__ . '/logs/cache.log')
    ->expirationTime('2 hours')
    ->flushAfter('1 day')
    ->build();

// Database
$options = OptionBuilder::forDatabase()
    ->table('cache_items')
    ->loggerPath(__DIR__ . '/logs/cache.log')
    ->expirationTime('30 minutes')
    ->flushAfter('7 days')
    ->build();
```

The `expirationTime()` and `flushAfter()` methods also support the **TimeBuilder** fluent API:

```
$options = OptionBuilder::forFile()
    ->dir(__DIR__ . '/cache')
    ->expirationTime()->hour(2)
    ->flushAfter()->day(1)
    ->build();
```

---

Encryption &amp; Compression
----------------------------

[](#encryption--compression)

### Encryption

[](#encryption)

Protect sensitive cached data with **AES-256-CBC** encryption. Each value gets a unique random IV — no two ciphertexts are alike, even for the same input.

```
$cache->useEncryption('your-secret-key-here');
$cache->putCache('token', 'sensitive-data');

// Stored encrypted, decrypted transparently on read
$token = $cache->getCache('token'); // "sensitive-data"
```

### Compression

[](#compression)

Reduce storage size with gzip compression — useful for large cached payloads:

```
$cache->useCompression();
$cache->putCache('large-dataset', $hugeArray);
```

Both can be combined:

```
$cache->useCompression();
$cache->useEncryption('my-key');

// Data is compressed, then encrypted before storage
$cache->putCache('secure-payload', $data);
```

---

Tags &amp; Namespaces
---------------------

[](#tags--namespaces)

### Tags

[](#tags)

Group related cache entries and invalidate them all at once:

```
$cache->putCache('user:1', $userData);
$cache->putCache('user:2', $otherUser);
$cache->tag('users', 'user:1', 'user:2');

// Later — flush everything tagged "users"
$cache->flushTag('users');
```

### Namespaces

[](#namespaces)

Logically separate cache entries to avoid key collisions:

```
$cache->putCache('config', $appConfig, 'app');
$cache->putCache('config', $apiConfig, 'api');

$cache->getCache('config', 'app'); // $appConfig
$cache->getCache('config', 'api'); // $apiConfig
```

---

PSR-16 SimpleCache
------------------

[](#psr-16-simplecache)

Need a standards-compliant interface? Wrap any `Cacheer` instance with the PSR-16 adapter:

```
use Silviooosilva\CacheerPhp\Psr\Psr16CacheAdapter;

$cache = new Cacheer(['cacheDir' => __DIR__ . '/cache']);
$cache->setDriver()->useFileDriver();

$psr16 = new Psr16CacheAdapter($cache);

$psr16->set('key', 'value', 3600);
$psr16->get('key');               // "value"
$psr16->get('missing', 'default'); // "default"
$psr16->delete('key');
$psr16->has('key');                // false

// Batch operations
$psr16->setMultiple(['a' => 1, 'b' => 2]);
$psr16->getMultiple(['a', 'b', 'c'], 'default');
$psr16->deleteMultiple(['a', 'b']);
$psr16->clear();
```

This adapter works with any library that accepts `Psr\SimpleCache\CacheInterface`.

---

Formatter
---------

[](#formatter)

Transform cached data on retrieval with the built-in formatter:

```
$cache->useFormatter();

$json   = $cache->getCache('user:1')->toJson();    // JSON string
$array  = $cache->getCache('user:1')->toArray();   // Array
$object = $cache->getCache('user:1')->toObject();  // stdClass
$string = $cache->getCache('user:1')->toString();  // String cast
```

---

API Reference
-------------

[](#api-reference)

### Write Operations

[](#write-operations)

MethodReturnsDescription`putCache($key, $data, $ns, $ttl)``bool`Store a value`add($key, $data, $ns, $ttl)``bool`Store only if key doesn't exist`putMany($items, $ns, $batch)``bool`Store multiple key-value pairs`forever($key, $data)``bool`Store with no expiration`appendCache($key, $data, $ns)``bool`Append to an existing value`increment($key, $amount, $ns)``bool`Increment a numeric value`decrement($key, $amount, $ns)``bool`Decrement a numeric value`renewCache($key, $ttl, $ns)``bool`Refresh a key's TTL`remember($key, $ttl, $fn)``mixed`Get or compute and store`rememberForever($key, $fn)``mixed`Get or compute and store forever### Read Operations

[](#read-operations)

MethodReturnsDescription`getCache($key, $ns)``mixed`Retrieve a cached value`getMany($keys, $ns)``array`Retrieve multiple values`getAll($ns)``array`Retrieve all values in namespace`getAndForget($key, $ns)``mixed`Retrieve and delete (atomic pop)`has($key, $ns)``bool`Check if a key exists### Delete Operations

[](#delete-operations)

MethodReturnsDescription`clearCache($key, $ns)``bool`Delete a single entry`flushCache()``bool`Delete all entries`tag($tag, ...$keys)``bool`Associate keys with a tag`flushTag($tag)``bool`Delete all entries for a tag### Configuration &amp; State

[](#configuration--state)

MethodReturnsDescription`setDriver()``CacheDriver`Switch storage backend`setConfig()``CacheConfig`Access configuration`useEncryption($key)``Cacheer`Enable AES-256 encryption`useCompression($on)``Cacheer`Enable gzip compression`useFormatter()``void`Enable output formatter`getOption($key, $default)``mixed`Get a config option`getOptions()``array`Get all config options`setOption($key, $value)``Cacheer`Set a config option`stats()``array`Driver, compression &amp; encryption status`isSuccess()``bool`Last operation succeeded?`getMessage()``string`Human-readable status message### TTL Formats

[](#ttl-formats)

CacheerPHP accepts TTL in multiple formats:

```
$cache->putCache('key', 'value', '', 3600);            // Seconds (int)
$cache->putCache('key', 'value', '', '2 hours');        // Human-readable string
$cache->putCache('key', 'value', '', new DateInterval('PT2H')); // DateInterval
$cache->forever('key', 'value');                        // No expiration
```

---

Requirements
------------

[](#requirements)

- **PHP 8.2+**
- `ext-pdo` — for database drivers
- `ext-openssl` — for encryption
- `ext-zlib` — for compression
- Redis server — when using the Redis driver

---

Testing
-------

[](#testing)

```
composer install
vendor/bin/pest
```

---

Documentation
-------------

[](#documentation)

Full documentation is available at [CacheerPHP Documentation](https://cacheerphp.com/docs/en/getting-started/).

---

Contributing
------------

[](#contributing)

Contributions are welcome! Please open an issue or submit a pull request.

---

License
-------

[](#license)

CacheerPHP is open-sourced software licensed under the [MIT license](https://opensource.org/licenses/MIT).

---

Support
-------

[](#support)

If CacheerPHP saves you time, consider supporting the project:

 [ ![Buy me a coffee](https://camo.githubusercontent.com/0cf29a542375e1a46e84d8bf5805a4e5c0a6ee98b6547ccdc0c55eed49d99c69/68747470733a2f2f63646e2e6275796d6561636f666665652e636f6d2f627574746f6e732f76322f64656661756c742d79656c6c6f772e706e67) ](https://buymeacoffee.com/silviooosilva)

###  Health Score

52

—

FairBetter than 96% of packages

Maintenance95

Actively maintained with recent releases

Popularity21

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity67

Established project with proven stability

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~11 days

Total

58

Last Release

53d ago

Major Versions

v1.5.0 → v2.0.02024-11-15

v2.3.1 → v3.0.02025-03-08

v3.7.0 → v4.0.02025-07-16

v4.7.7 → v5.0.02026-04-03

PHP version history (2 changes)v1.0.0PHP &gt;=8.0

v5.0.0PHP &gt;=8.2

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/66147538?v=4)[Sílvio Silva](/maintainers/silviooosilva)[@silviooosilva](https://github.com/silviooosilva)

---

Top Contributors

[![silviooosilva](https://avatars.githubusercontent.com/u/66147538?v=4)](https://github.com/silviooosilva "silviooosilva (334 commits)")

---

Tags

arrayscachedatabasefilespackagephpredispsr-3phpdatabaseperformancemysqlsqlitepgsqlrediscachecachingpsr-16nosqlpredisoptimizationfile cachespeedoptimizercache managerSilviooosilvadatabase-cache

###  Code Quality

TestsPHPUnit

Code StylePHP CS Fixer

### Embed Badge

![Health badge](/badges/silviooosilva-cacheer-php/health.svg)

```
[![Health](https://phpackages.com/badges/silviooosilva-cacheer-php/health.svg)](https://phpackages.com/packages/silviooosilva-cacheer-php)
```

###  Alternatives

[laravel/framework

The Laravel Framework.

34.8k543.8M20.0k](/packages/laravel-framework)[doctrine/dbal

Powerful PHP database abstraction layer (DBAL) with many features for database schema introspection and management.

9.7k605.0M6.8k](/packages/doctrine-dbal)[matthiasmullie/scrapbook

Scrapbook is a PHP cache library, with adapters for e.g. Memcached, Redis, Couchbase, APCu, SQL and additional capabilities (e.g. transactions, stampede protection) built on top.

3232.8M44](/packages/matthiasmullie-scrapbook)[tempest/framework

The PHP framework that gets out of your way.

2.2k34.4k15](/packages/tempest-framework)[apix/cache

A thin PSR-6 cache wrapper with a generic interface to various caching backends emphasising cache taggging and indexing to Redis, Memcached, PDO/SQL, APC and other adapters.

117548.2k6](/packages/apix-cache)[tommyknocker/pdo-database-class

Framework-agnostic PHP database library with unified API for MySQL, MariaDB, PostgreSQL, SQLite, MSSQL, and Oracle. Query Builder, caching, sharding, window functions, CTEs, JSON, migrations, ActiveRecord, CLI tools, AI-powered analysis. Zero external dependencies.

846.1k](/packages/tommyknocker-pdo-database-class)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
