thybag/php-simple-cache

快速、健谈的文件缓存助手

dev-master 2018-12-09 16:12 UTC

This package is auto-updated.

Last update: 2024-09-10 05:25:58 UTC


README

一个简单的PHP文件缓存库。不建议在生产环境中使用。许可证:MIT

功能

  • 可选的绕过缓存功能(用于调试)
  • 可读的缓存键/路径
  • 在无法加载新数据时回退到旧缓存
  • 健谈的日志记录(需要PSR日志记录器)

用法

composer require thybag/php-simple-cache

// Standard
$cache = new \thybag\PhpSimpleCache\Cache;
$result = $cache->get("key");

// static
$result = \thybag\PhpSimpleCache\StaticCache::get("key")

方法

  • read($cache_key, $max_age, $fallback) - 从缓存中读取一个项目。如果项目过旧,则返回回退值。
  • write($cache_key, $data) - 将数据写入缓存
  • delete($cache_key, $recursivedDelete) - 从缓存中删除项目(或可选地删除整个文件夹)
  • has($key, $max_age) - 我们是否有缓存的非陈旧版本
  • age($cache_key) - 缓存项的当前年龄(如果没有找到缓存,则返回false)
  • get($cache_key, $callback, $max_page) - 运行回调,缓存内容

可以通过以下方式更改设置:

  • setLogger(PSR日志记录器)
  • setOptions(['cache_path'=>, 'allow_cache_bypass', 'cache_bypass_keyword', 'default_ttl'])