gustav / cache
一个小巧简单的PHP缓存系统
v0.7
2020-07-11 13:21 UTC
Requires
- php: ^7.4
- ext-mbstring: *
- gustav/utils: ^0.1
- psr/cache: ^1.0
- psr/simple-cache: ^1.0
Requires (Dev)
- phpunit/phpunit: ~9.2
README
一个小巧简单的PHP缓存系统,实现了 PSR-6 接口。
实现
- 文件系统:每个缓存项池都是一个简单的文件。缓存项使用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。