
內容簡介
Jinx Fast-Cache 提供了一個簡單但有效的全頁面快取方式供 WordPress 使用。
它會生成靜態 HTML 檔案,並且會利用您的伺服器重寫規則來呼叫這些檔案。
透過這個功能,系統可以略過整個 PHP 處理過程,並且只輸出一個簡單的 HTML 檔案,避免不必要的開銷。
使用方法
在啟用外掛之後,它會修改您的 htaccess 檔案。如果這不能被執行,請確認自行輸入以下規則:
# BEGIN Jinx Fast-Cache
RewriteEngine On
RewriteBase /
RewriteCond %{DOCUMENT_ROOT}/wp-content/jinx-fast-cache/%{HTTP_HOST}/%{REQUEST_URI}/%{QUERY_STRING}/index.html -s
RewriteCond %{REQUEST_METHOD} GET
RewriteRule .* /wp-content/jinx-fast-cache/%{HTTP_HOST}/%{REQUEST_URI}/%{QUERY_STRING}/index.html [L]
# END Jinx Fast-Cache
如果使用 nginx,請確認加入以下規則:
set $cache_path false;
if ($request_method = GET) {
set $cache_path /wp-content/jinx-fast-cache/$host/$uri/$args/index.html;
}
location / {
try_files $cache_path $uri $uri/ /index.php?$query_string;
}
您可以透過管理列的按鈕,對單一或多個 URL 進行快取清空、預先加載或更新 (清空並預先加載)。
預設情況下,每當文章完成儲存,所有文章會自動預先加載,而在文章被刪除或變成草稿之後,就會自動清空快取。
進行預先加載時,系統會建立一個工作清單,並在定期工作 (cron) 中處理。當預先加載單篇文章時,它會跳過工作清單。
插件會在完成更新之後自動清空快取,並且預先加載快取。
開發人員
篩選器
Jinx Fast-Cache 非常適合開發人員使用。目前並無後台面板可供使用,但您可以透過篩選器修改許多功能行為。
jinx_fast_cache:回傳 true(預設值)或 false,以控制是否快取該 URL。
jinx_fast_cache_post_types: 控制應該快取的文章類型。預設情況下,快取所有「可供公開查詢」和「頁面」的文章類型。
jinx_fast_cache_posts: 篩選應該快取的文章。
jinx_fast_cache_taxonomies: 控制應該快取的分類法。預設情況下,快取所有「可供公開查詢」的分類法。
jinx_fast_cache_terms: 篩選應該快取的關聯詞。
jinx_fast_cache_output: 改寫 HTML 內容以使用快取檔案。
jinx_fast_cache_minify: 回傳 true(預設值)或 false,以指定是否將輸出進行最小化。
jinx_fast_cache_flush: 控制應該清除的 URL。此功能可用於清空相關 URL,例如您的首頁。
jinx_fast_cache_warm: 控制應該預先加載的 URL。此功能可用於預先加載相關 URL,例如您的首頁。
jinx_fast_cache_interval: 變更排程工作時間間隔 (預設為 60)。
jinx_fast_cache_queue_size: 變更在執行排程工作期間會處理的 URL 數目 (預設為 10)。當設為小於或等於 0 時,將處理所有 URL。這可能會造成大量負載,尤其是當您的網站有很多 URL 時。
插入
Jinx Fast-Cache 還提供了插入動態內容的功能。例如,如果您要在頁面上列印使用者姓名,您可以通過 AJAX 進行插入。
請注意,第一個參數是占位符內容。透過這個方法,當不使用外掛時,就不會發生任何問題。您可以正常載入模板,或是顯示像「正在載入」之類的提示文字。
插入模板:
do_action('jinx_fast_cache_inject_template', 'user');
外掛標籤
開發者團隊
原文外掛簡介
Jinx Fast-Cache provides a simple but highly efficient way to implement full-page caching. It generates static HTML files of your pages, which are then served directly by your web server (Apache or Nginx).
By bypassing the entire PHP process and database queries, your server load is significantly reduced and your website response time becomes near-instant. Unlike many other plugins, Jinx Fast-Cache is built with a developer-first approach, working primarily with URLs and offering deep integration via filters and actions.
Usage
Server Configuration
To serve the cached files directly, you must add rewrite rules to your server configuration.
For Apache (.htaccess):
The plugin will attempt to modify your .htaccess automatically. If it fails, add this manually:
# BEGIN Jinx Fast-Cache
RewriteEngine On
RewriteBase /
RewriteCond %{DOCUMENT_ROOT}/wp-content/jinx-fast-cache/%{HTTP_HOST}/%{REQUEST_URI}/%{QUERY_STRING}/index.html -s
RewriteCond %{REQUEST_METHOD} GET
RewriteRule .* /wp-content/jinx-fast-cache/%{HTTP_HOST}/%{REQUEST_URI}/%{QUERY_STRING}/index.html [L]
# END Jinx Fast-Cache
For Nginx:
Add the following logic to your server block:
set $cache_path false;
if ($request_method = GET) {
set $cache_path /wp-content/jinx-fast-cache/$host/$uri/$args/index.html;
}
location / {
try_files $cache_path $uri $uri/ /index.php?$query_string;
}
Cache Management
Admin Bar: You can flush (clear), warm (generate), or refresh (flush & warm) single or multiple URLs directly from the admin bar.
Automatic Updates: Posts are automatically “warmed” after saving and “flushed” when deleted or set to draft.
Background Processing: The warming process uses a background queue handled via WordPress Cron to ensure server stability. Single post warming skips the queue for immediate results.
Plugin Updates: The cache is automatically refreshed after the plugin is updated.
Developer API
Jinx Fast-Cache is highly extensible. While a settings panel is available, developers can fine-tune every detail via filters and actions.
1. Filters
jinx_fast_cache_active: Toggle caching for specific conditions (default: false).
jinx_fast_cache_post_types: Define which post types should be cached (default: ‘page’ and ‘publicly_queryable’ types).
jinx_fast_cache_posts: Filter the specific list of post objects to be cached.
jinx_fast_cache_taxonomies: Define which taxonomies are cacheable.
jinx_fast_cache_terms: Filter the specific list of terms to be cached.
jinx_fast_cache_output: Modify the raw HTML content before it is saved to the cache file.
jinx_fast_cache_minify: Enable/disable HTML minification (default: false).
jinx_fast_cache_flush: Define additional related URLs that should be cleared when a specific page is flushed.
jinx_fast_cache_warm: Define additional related URLs that should be preloaded when a specific page is warmed.
jinx_fast_cache_queue_interval: Adjust the cron task frequency for the warming queue (default: 60s).
jinx_fast_cache_queue_size: Adjust the batch size per cron task (default: 10). Set to <= 0 to process everything at once (Caution: High server load).
jinx_fast_cache_gc_interval: Adjust the Garbage Collector frequency to remove invalid files (default: 60s).
jinx_fast_cache_ignore_logged_in_users: Toggle caching for logged-in users (default: true).
jinx_fast_cache_ignore_404: Toggle if 404 error pages should be cached (default: false).
jinx_fast_cache_query_params: Define allowed query parameters. Return __return_empty_array to ignore all parameters.
jinx_fast_cache_refresh_on_upgrade: Toggle the full cache refresh after plugin updates (default: true).
jinx_fast_cache_ttl: Define the cache lifetime (TTL). Supports seconds (e.g., 3600) or strings (e.g., ’12 hours’, ‘1 week’).
2. Dynamic Injections (AJAX)
Since static HTML files cannot execute PHP, Jinx allows you to “inject” dynamic content (like a user’s name or a shopping cart) via AJAX.
Injecting a Template Part:
do_action('jinx_fast_cache_inject_template', 'template-slug', 'Placeholder text...');
Injecting via Function Call:
You can call any public function or class method:
do_action('jinx_fast_cache_inject', 'date', ['Y']);
do_action('jinx_fast_cache_inject', ['MyClass', 'myMethod'], [$arg1, $arg2]);
Using Shortcodes:
[jinx_fast_cache_inject placeholder="Loading..."] Your dynamic content here [/jinx_fast_cache_inject]
JS Callbacks:
Trigger custom JavaScript after the content has been injected:
$('.element').on('jinx-fast-cache-inject', (e) => { /* Handle injection */ });
element.addEventListener('jinx-fast-cache-inject', (e) => { /* Handle injection */ }, false);
3. URL Tags & Relations
Tags are a powerful way to link multiple URLs together. If one URL is flushed, all other URLs sharing the same tag will also be purged. This is perfect for linking a “Latest Posts” widget on your homepage to your single post entries.
Via Shortcode:
[jinx_fast_cache tags="news,homepage"]
Via Action:
do_action('jinx_fast_cache', ['tags' => 'tag1,tag2']);
do_action('jinx_fast_cache', ['tags' => ['tag1', 'tag2']]);
4. Per-Page Cache Duration (TTL)
Override the global TTL for specific high-traffic or highly dynamic pages.
Via Shortcode:
[jinx_fast_cache ttl="3600"] or `[jinx_fast_cache ttl="12 hours"]`
Via Action:
do_action('jinx_fast_cache', ['ttl' => 3600]);
Combined Call (Tags + TTL):
do_action('jinx_fast_cache', ['ttl' => 3600, 'tags' => ['foo', 'bar']]);
Roadmap
– [x] Release the plugin
– [x] Add HTML minification for output
– [x] Allow injection of dynamic rendered templates using ajax requests
– [x] Add taxonomies
– [x] Provide scheduled tasks
– [x] Add admin columns for cache status
– [x] Provide exclude option for posts and terms in backend
– [x] Add multisite support
– [x] Flush and warm after update complete
– [x] Add possibility to ignore 404
– [x] Allow query params to be excluded or totally ignored
– [x] Provide cache duration
– [x] Provide admin panel to change options
– [x] Add tags to flush related pages
– [x] Add shortcode for injects
– [x] Add JS events for injects
– [x] Gutenberg inject block
