数组缓存适配器
通常,此适配器对于测试目的非常有用,因为它的内容存储在内存中,并且不会以任何方式持久保存在运行的 PHP 进程之外。由于 getValues() 方法,它在预热缓存时也可能很有用。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
use Symfony\Component\Cache\Adapter\ArrayAdapter;
$cache = new ArrayAdapter(
// 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 current PHP process finishes)
$defaultLifetime = 0,
// if true, the values saved in the cache are serialized before storing them
$storeSerialized = true,
// the maximum lifetime (in seconds) of the entire cache (after this time, the
// entire cache is deleted to avoid stale data from consuming memory)
$maxLifetime = 0,
// the maximum number of items that can be stored in the cache. When the limit
// is reached, cache follows the LRU model (least recently used items are deleted)
$maxItems = 0,
// optional implementation of the Psr\Clock\ClockInterface that will be used
// to calculate the lifetime of cache items (for example to get predictable
// lifetimes in tests)
$clock = null,
);
7.2
可选的 $clock
参数在 Symfony 7.2 中引入。
这项工作,包括代码示例,根据 Creative Commons BY-SA 3.0 许可获得许可。