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.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/update-docs
- dev-feature/option-builder-for-database-and-redis
- dev-codex/move-cacheer-methods-for-static-access
- dev-feature/performance-test-cacheer
This package is auto-updated.
Last update: 2025-09-01 13:05:08 UTC
README
CacheerPHP is a minimalist PHP caching library. Version 4 brings a more robust API, optional compression and encryption and support for multiple backends including files, databases and Redis.
Features
- Multiple storage drivers: file system, databases (MySQL, PostgreSQL, SQLite), Redis and in-memory arrays.
- Customizable expiration: define precise TTL (Time To Live) values.
- Automatic and manual flushing: clean cache directories with
flushAfter
or on demand. - Namespaces: group entries by category for easier management.
- Flexible output formatting: return cached data as JSON, arrays, strings or objects.
- Compression & encryption: reduce storage footprint and secure cache contents.
- OptionBuilder: fluent builders to configure File, Redis and Database drivers without typos (supports default TTL via
expirationTime
and auto-flush viaflushAfter
). - Advanced logging and statistics: monitor hits/misses and average times (coming soon).
Requirements
- PHP 8.0+
- Optional extensions: PDO drivers for MySQL, PostgreSQL or SQLite
- Redis server and
predis/predis
if using the Redis driver
Installation
Install via Composer:
composer require silviooosilva/cacheer-php
Configuration
Copy the example environment file and adjust the settings for your environment:
cp .env.example .env
Environment variables control database and Redis connections. See Configuration for the full list.
Quick start
require_once __DIR__ . '/vendor/autoload.php'; use Silviooosilva\CacheerPhp\Cacheer; $key = 'user_profile_1234'; $value = ['id' => 123, 'name' => 'John Doe']; // Configure cache and driver statically Cacheer::setConfig()->setTimeZone('UTC'); Cacheer::setDriver()->useArrayDriver(); // Static usage with boolean return Cacheer::putCache($key, $value); if (Cacheer::has($key)) { $cached = Cacheer::getCache($key); var_dump($cached); } // Dynamic usage and isSuccess() $cache = new Cacheer([ 'cacheDir' => __DIR__ . '/cache', ]); $cache->has($key); if ($cache->isSuccess()) { $cached = $cache->getCache($key); var_dump($cached); } else { echo $cache->getMessage(); } // Alternatively, check the state via isSuccess() $cache->has($key); if ($cache->isSuccess()) { $cached = $cache->getCache($key); var_dump($cached); }
Documentation
-
English
-
Português (PT-BR)
Runnable PHP samples live in the Examples/
directory.
Testing
After installing dependencies, run the test suite with:
vendor/bin/phpunit
Contributing
Contributions are welcome! Please open an issue or submit a pull request on GitHub.
License
CacheerPHP is open-sourced software licensed under the MIT license.
Support
If this project helps you, consider buying the maintainer a coffee.