silviooosilva/cacheer-php
最新稳定版本:v4.7.6
Composer 安装命令:
composer require 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.
关键字:
README 文档
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
flushAfteror 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
expirationTimeand 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/predisif 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
Full documentation is available at CacheerPHP Documentation.
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.
统计信息
- 总下载量: 87
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 28
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2024-07-18
