APCu 快取介面卡
此介面卡是一種高效能的共享記憶體快取。它可以顯著提升應用程式的效能,因為其快取內容儲存在共享記憶體中,而共享記憶體是比許多其他元件(例如檔案系統)快得多的元件。
警告
需求: 必須安裝並啟用 APCu 擴充功能 才能使用此介面卡。
ApcuAdapter 可以選擇性地提供命名空間、預設快取生命週期和快取項目版本字串作為建構子參數
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
use Symfony\Component\Cache\Adapter\ApcuAdapter;
$cache = new ApcuAdapter(
// 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 APCu memory is cleared)
$defaultLifetime = 0,
// when set, all keys prefixed by $namespace can be invalidated by changing
// this $version string
$version = null
);
警告
不建議在寫入/刪除繁重的工作負載中使用此介面卡,因為這些操作會導致記憶體碎片化,從而導致效能顯著下降。
提示
此介面卡的 CRUD 操作特定於其執行的 PHP SAPI。這表示使用 CLI 的快取操作(例如新增、刪除等)在 FPM 或 CGI SAPI 下將不可用。
本作品,包括程式碼範例,依據 創用 CC BY-SA 3.0 授權條款授權。