跳到內容

Proxy Cache Adapter

編輯此頁

此适配器封裝了符合 PSR-6 規範的 快取項目池介面。它用於將應用程式的快取項目池實作與 Symfony Cache Component 整合,方法是使用任何 Psr\Cache\CacheItemPoolInterface 的實作。

它也可以用於在將項目儲存到裝飾的池之前自動為所有鍵添加前綴,有效地允許從單個池建立多個命名空間池。

此适配器預期一個 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 授權條款發佈。
目錄
    版本