跳到內容

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 授權條款授權。
目錄
    版本