gustav/cache

一个小巧简单的PHP缓存系统

v0.7 2020-07-11 13:21 UTC

This package is auto-updated.

Last update: 2024-09-11 22:17:49 UTC


README

一个小巧简单的PHP缓存系统,实现了 PSR-6 接口。

Build Status

实现

  • 文件系统:每个缓存项池都是一个简单的文件。缓存项使用PHP的默认序列化方法保存。
  • 调试:缓存项池不会持久化。这只是为了测试目的。请勿在生产环境中使用此实现。

用法

//configure the system
$config = new \Gustav\Cache\Configuration();
$config->setDirectory("path/to/my/cache/files/");

//load cache manager
$manager = \Gustav\Cache\ACacheManager::getInstance($config);

//fetch the item pool
$pool = $manager->getItemPool("myFileName", $myCreatorFunction);

配置

您可以在 \Gustav\Orm\Configuration 中设置以下配置

  • setImplementation(string):设置要使用的缓存管理器实现。默认是 \Gustav\Cache\Filesystem\CacheManager(即文件系统缓存)。
  • setDirectory(string):设置文件系统中的目录,用于保存缓存池文件。没有默认值。
  • setDefaultExpiration(integer):设置缓存项的默认存活时间,如果您在 \Gustav\Cache\CacheItem 中没有明确设置。考虑 0 和更低表示项将不会过期。默认是 0
  • getLogConiguration(): \Gustav\Utils\Log\Configuration / setLogConfiguration(\Gustav\Utils\Log\Configuration):配置用于此缓存实现的错误日志。默认情况下,它使用Utils的默认配置。有关更多信息,请参阅 Gustav Utils