Doctrine DBAL 缓存适配器
Doctrine DBAL 适配器将缓存项存储在 SQL 数据库的表中。
注意
此适配器实现了 PruneableInterface,允许通过调用 prune()
方法手动修剪过期的缓存条目。
DoctrineDbalAdapter 需要一个 Doctrine DBAL 连接,或 Doctrine DBAL URL 作为其第一个参数。您可以传递命名空间、默认缓存生命周期和选项数组作为其他可选参数。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
use Symfony\Component\Cache\Adapter\DoctrineDbalAdapter;
$cache = new DoctrineDbalAdapter(
// a Doctrine DBAL connection or DBAL URL
$databaseConnectionOrURL,
// the 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 database table is truncated or its rows are otherwise deleted)
$defaultLifetime = 0,
// an array of options for configuring the database table and connection
$options = []
);
注意
DBAL 连接默认是延迟加载的;可能需要一些额外的选项来检测数据库引擎和版本,而无需打开连接。
该适配器使用针对其连接的数据库服务器优化的 SQL 语法。已知以下数据库服务器兼容:
- MySQL 5.7 及更高版本
- MariaDB 10.2 及更高版本
- Oracle 10g 及更高版本
- SQL Server 2012 及更高版本
- SQLite 3.24 或更高版本
- PostgreSQL 9.5 或更高版本
注意
较新版本的 Doctrine DBAL 可能会提高这些最低版本要求。请查看 Doctrine DBAL 平台 手册页面,以确定您的数据库服务器是否与已安装的 Doctrine DBAL 版本兼容。
本作品,包括代码示例,根据 Creative Commons BY-SA 3.0 许可协议获得许可。