新增了一个“Null”适配器 

Contributed by
Titouan Galopin
in #18825.

全新的 Symfony\Component\Cache\Adapter\NullAdapter 是一个特殊的 cache adapter 用于关闭缓存(它扔掉存在它上面的所有元素,并且对所有读取和存储动作返回 false)。这个适配器主要是对测试有用。

增加了一个更快的文件适配器 

全新的 Symfony\Component\Cache\Adapter\PhpFilesAdapter 与已经存在的 FilesystemAdapter 非常相似,但是它在当服务器使用Opcache时会有更好的性能。

技巧点在于,当元素被存储时,新的适配器会创建一个在 fetch() 操作过程中被包容的PHP文件。这能让OPcache把那些文件缓存到内存中。在我们的基准测试中, PhpFilesAdapter 在读取操作上3.5倍快于 FilesystemAdapter,但在写入上略慢,因此最适于用在文件不怎么被改变的情况下。

增加了一个PDO和Doctrine DBAL适配器 

Contributed by
Nicolas Grekas
in #19519.

全新的 Symfony\Component\Cache\Adapter\PdoAdapter 允许使用任何兼容DBAL的数据库来作为你的缓存存储。它的实现过程大幅借鉴了 PdoSessionHandler。例如,创建一个基于SQLite的缓存,执行以下代码:

1
2
3
4
5
use Symfony\Component\Cache\Adapter\PdoAdapter;
 
$dbFilePath = tempnam(sys_get_temp_dir(), 'sf_sqlite_cache');
$pool = new PdoAdapter('sqlite:'.$dbFilePath);
$pool->createTable();

增加了一个通用的“tag-aware”适配器 

Contributed by
Nicolas Grekas
in #19524.

基于Tag的无效化,是Symfony为缓存失效而提供的一种架构,它是一个清除所有“与你的model状态改变”有关的被缓存元素的过程。

在Symfony 3.2中,一个全新的 Symfony\Component\Cache\Adapter\TagAwareAdapter 类和一个 Symfony\Component\Cache\Adapter\TagAwareAdapterInterface 接口,允许把任何缓存适配器转换成一个tag-aware adapter。

TagAwareAdapter类的构造器接收两个参数:第一个是用于存储元素的cache adapter,第二个可选参数是用于缓存tags的adapter。这可以令你,比如,使用文件系统或数据库来存储巨大元素,以及使用一个用于tags的Redis缓存,以实现超高速的失效检查(to have ultra-fast invalidation checks):

1
2
3
4
5
6
7
8
use Symfony\Component\Cache\Adapter\TagAwareAdapter;
use Symfony\Component\Cache\Adapter\FilesystemAdapter;
use Symfony\Component\Cache\Adapter\RedisAdapter;
 
$cache = new TagAwareAdapter(
    new FilesystemAdapter(),
    new RedisAdapter('redis://localhost')
);

增加了一条命令用于清除缓存池 

Contributed by
Nicolas Grekas
in #19891.

FrameworkBundle现在包含了一个 cache:pool:clear 命令,接受一或多个服务名作为参数。这些服务是待清除的缓存池(cache pools to clear)或是待调用的缓存清理器服务(cache clearer services):

1
$  ./bin/console cache:pool:clear app.cache app.cache.products