內容簡介
此外掛需要 PHP 版本 5.3.6 或更高版本,並且必須啟用 持久化快取後端 以使用 WordPress 物件快取。
新增緩存特定網站區域的能力。此外掛適用於無法使用全站頁面緩存或有大量網頁且頻繁變更的網站。
可將 WP_Query(繞過資料庫查詢) 的整個迴圈進行快取,或僅快取迴圈的 HTML 輸出,當查詢結果有變更(例如新增留言、編輯文章、編輯文章元資料等)時,快取將會失效並重新生成。
使用範例:
<?php if ( ! WP_Fragment_Cache::output( $wp_query_or_blockname, $duration ) ): ?>
// 需要進行緩存的內容
<?php WP_Fragment_Cache::store(); ?>
<?php endif; ?>
參數:
$wp_query_or_blockname
(mixed/string) (選填) WP_Query(WP_Comment_Query) 回傳結果或字串。
預設值:呼叫啟動時的檔案和行數(例如 widgets/most-commented.php:18)。
$duration
(int/string) (選填) 定義快取保留時間的秒數。若設為 0,快取將不會過期。若設為 "only_today" 字串,快取將於當天結束時過期。您可以使用 WordPress 時間常數。
預設值:86400 (一天)。
進階使用:
請參考 GitHub 上的 wiki 頁面。
外掛標籤
開發者團隊
原文外掛簡介
This plugin requires PHP version 5.3.6 or greater and can’t be activated without a persistent backend for the WordPress Object Cache.
Adds ability to cache particular sections of your site. This plugin is for people who can’t use a full page cache or for sites with lots of pages and with frequent changes.
It can cache entire loops with the WP_Query(bypassing the database queries) or only the html output of the loop and if the query results has changed(comment added, post was edited, postmeta has changed …) the cache will be invalidated and regenerated.
Example usage:
//content to be cached
Parameters:
$wp_query_or_blockname
(mixed/string) (optional) a WP_Query(WP_Comment_Query) result or a string.
Default: the file and the line where the call was initiated(e.g. widgets/most-commented.php:18).
$duration
(int/string) (optional) Defines how many seconds to keep the cache for. If you pass 0 the cache will not expire. If you pass the string “only_today” the cache will expire at the end of the current day. You can use WordPress Time Constants.
Default: 86400 (one day).
Advanced usage:
See the wiki pages on GitHub
