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.
Requires
- php: >=8.0
- ext-openssl: *
- ext-pdo: *
- ext-zlib: *
- predis/predis: ^2.3
- vlucas/phpdotenv: ^5.6
Requires (Dev)
- phpunit/phpunit: ^11.2
- dev-main
- v4.7.7
- v4.7.6
- v4.7.5
- v4.7.3
- v4.7.2
- v4.7.0
- v4.6.4
- v4.6.2
- v4.6.1
- v4.6.0
- v4.5.0
- v4.4.1
- v4.4.0
- v4.3.0
- v4.2.0
- v4.1.1
- v4.1.0
- v4.0.3
- v4.0.2
- v4.0.0
- v3.7.0
- v3.6.1
- v3.6.0
- v3.5.2
- v3.5.1
- v3.5.0
- v3.4.4
- v3.4.2
- v3.4.1
- v3.4.0
- v3.3.0
- v3.2.0
- v3.1.1
- v3.1.0
- v3.0.4
- v3.0.3
- v3.0.2
- v3.0.1
- v3.0.0
- v2.3.1
- v2.3.0
- v2.2.1
- v2.2.0
- v2.1.0
- v2.0.0
- v1.5.0
- v1.4.1
- v1.4.0
- v1.3.0
- v1.2.0
- v1.1.0
- v1.0.0
- dev-feature/performance-test-cacheer
This package is auto-updated.
Last update: 2026-03-08 01:59:09 UTC
README
CacheerPHP is a minimalist PHP caching library with multiple backends (file, database, Redis and array), optional compression/encryption and a small but complete API.
Features
- Multiple storage drivers: file system, databases (MySQL, PostgreSQL, SQLite), Redis and in-memory arrays.
- TTL, namespaces and tags for organization and invalidation.
- Auto-flush support with
flushAfter. - Optional compression and encryption.
- Formatter helper for JSON/array/object output.
Requirements
- PHP 8.0+
- PDO drivers for database backends
- Redis server when using the Redis driver
Installation
composer require silviooosilva/cacheer-php
Configuration
Copy the example environment file and adjust as needed:
cp .env.example .env
Minimum variables:
DB_CONNECTION=sqlite REDIS_HOST=127.0.0.1 REDIS_PORT=6379
For MySQL/PostgreSQL:
DB_CONNECTION=mysql DB_HOST=127.0.0.1 DB_PORT=3306 DB_DATABASE=cacheer_db DB_USERNAME=root DB_PASSWORD=secret
Quick start
require_once __DIR__ . '/vendor/autoload.php'; use Silviooosilva\CacheerPhp\Cacheer; Cacheer::setConfig()->setTimeZone('UTC'); Cacheer::setDriver()->useArrayDriver(); Cacheer::putCache('user:1', ['id' => 1, 'name' => 'John']); if (Cacheer::has('user:1')) { $user = Cacheer::getCache('user:1'); }
File driver with options:
$cache = new Cacheer([ 'cacheDir' => __DIR__ . '/cache', 'loggerPath' => __DIR__ . '/cacheer.log', 'expirationTime' => '1 hour', 'flushAfter' => '1 day', ]);
Drivers
Cacheer::setDriver()->useFileDriver(); Cacheer::setDriver()->useDatabaseDriver(); Cacheer::setDriver()->useRedisDriver(); Cacheer::setDriver()->useArrayDriver();
Return contract
putCache,appendCache,clearCache,flushCache,renewCache,putMany,tag,flushTagreturnbool.hasreturnsbool.getCachereturnsmixed|null(orCacheDataFormatterwhen formatter is enabled).getManyreturnsarray(orCacheDataFormatterwhen formatter is enabled).getAllreturnsarray(orCacheDataFormatterwhen formatter is enabled).getMessagereturnsstring;isSuccessreturnsbool.
Formatter usage:
$cache->useFormatter(); $json = $cache->getCache('user:1')->toJson();
Testing
vendor/bin/phpunit
Documentation
Full documentation is available at CacheerPHP Documentation.
Contributing
Contributions are welcome. Please open an issue or submit a pull request.
License
CacheerPHP is open-sourced software licensed under the MIT license.
Support
If this project helps you, consider buying the maintainer a coffee.
