代理缓存适配器
此适配器封装了一个 PSR-6 兼容的 缓存项池接口。它用于通过使用 Psr\Cache\CacheItemPoolInterface
的任何实现,将你应用程序的缓存项池实现与 Symfony Cache 组件 集成。
它也可以用于在存储条目到装饰器池之前自动为所有键添加前缀,从而有效地从单个池中创建多个命名空间池。
此适配器期望一个 Psr\Cache\CacheItemPoolInterface
实例作为其第一个参数,并可选地将命名空间和默认缓存生命周期作为其第二个和第三个参数
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
use Psr\Cache\CacheItemPoolInterface;
use Symfony\Component\Cache\Adapter\ProxyAdapter;
// create your own cache pool instance that implements
// the PSR-6 CacheItemPoolInterface
$psr6CachePool = ...
$cache = new ProxyAdapter(
// a cache pool instance
CacheItemPoolInterface $psr6CachePool,
// a string prefixed to the keys of the items stored in this cache
$namespace = '',
// the default lifetime (in seconds) for cache items that do not define their
// own lifetime, with a value 0 causing items to be stored indefinitely (i.e.
// until the cache is cleared)
$defaultLifetime = 0
);
这项工作,包括代码示例,根据 Creative Commons BY-SA 3.0 许可证获得许可。