effectra / cache
Effectra 缓存包。
v1.0.0
2023-07-12 13:12 UTC
Requires
- predis/predis: *
- psr/cache: *
- psr/simple-cache: ^3.0
README
Effectra\Cache 是一个基于 PSR-16 (Simple Cache) 标准提供缓存实现的包。它包括可以用于在各种缓存存储系统中存储和检索数据的缓存类。
特性
- PSR-16 兼容性:实现了
Psr\SimpleCache\CacheInterface
。 - 易于集成:提供不同缓存存储系统的缓存实现。
- 灵活配置:支持基于所选存储系统的不同缓存配置。
- 简洁的 API:提供直观的 API 用于缓存数据。
安装
您可以通过 Composer 安装此包。在项目目录中运行以下命令
composer require effectra/cache
用法
该包包括各种缓存类,每个类代表不同的缓存存储系统。您可以根据需求选择所需的缓存类。以下是一个使用 JsonCache
类的示例
use Effectra\Cache\Psr16\JsonCache; // Create an instance of the JsonCache class with the cache directory $cache = new JsonCache('/path/to/cache/directory'); // Store a value in the cache with a key and optional time-to-live (TTL) $cache->set('key', 'value', 3600); // Cache value with a TTL of 1 hour // Retrieve a value from the cache $result = $cache->get('key'); // Delete a value from the cache $cache->delete('key'); // Clear the entire cache $cache->clear();
可用的缓存类
FileCache
:在文件系统中使用单独的文件存储缓存数据。JsonCache
:在文件系统中使用 JSON 文件存储缓存数据。RedisCache
:在 Redis 服务器中存储缓存数据。
有关方法和用法的更多详细信息,请参阅相应类的文档和 PSR-16 规范。
要求
- PHP >= 7.2
- Composer(用于安装)
贡献
欢迎贡献!如果您发现任何问题或有改进建议,请在此 GitHub 仓库中打开一个问题或提交一个 pull request。
许可证
此包是开源的,可在 MIT 许可证 下使用。