[WordPress] 外掛分享: WP Super Cache

WordPress 外掛 WP Super Cache 的封面圖片。

前言介紹

  • 這款 WordPress 外掛「WP Super Cache」是 2007-11-04 上架。
  • 目前有 1000000 個安裝啟用數。
  • 上一次更新是 2025-04-04,距離現在已有 29 天。
  • 外掛最低要求 WordPress 6.6 以上版本才可以安裝。
  • 外掛要求網站主機運作至少需要 PHP 版本 7.2 以上。
  • 有 1337 人給過評分。
  • 論壇上目前有 10 個提問,問題解答率 100% ,不低,算是個很有心解決問題的開發者團隊了!

外掛協作開發者

donncha | adnan007 | dilirity | pyronaur | thingalon | automattic | mikemayhem3030 |

外掛標籤

cache | caching | WP Cache | performance | WP Super Cache |

內容簡介

本外掛可以從您的動態 WordPress 部落格生成靜態 HTML 檔案。在產生 HTML 檔案後,您的網頁伺服器會傳送該檔案,而不是處理比較沉重、耗費更多資源的 WordPress PHP 程式。

絕大部分的使用者都會收到靜態 HTML 檔案:

未登入的使用者。
未在您的部落格留言的使用者。
或是未查看有密碼保護文章的使用者。

99% 的訪客都會收到靜態 HTML 檔案。一個快取檔案可以被呼叫數千次。其他訪客將會收到針對他們造訪而量身打造的快取檔案。如他們已登入,或已留言,這些詳情將會被顯示和快取。

此外掛提供三種方式來提供快取檔案(由快到慢排列):

專家模式。使用 Apache mod_rewrite(或您的網頁伺服器支援的類似模組)是最快速的方法,可以提供「超級快取」靜態 HTML 檔案。這是完全繞過 PHP 的方式,非常快速。如果您的伺服器經受得起洪水般大量的訪問,這種方法會比較容易應付,因為這種請求是比較「輕量」的。此方法需要 Apache mod_rewrite 模組(如果您使用自訂連結,很有可能已經安裝)和更改您的 .htaccess 檔案,這本身有一定的風險,如果修改不當可能會導致網站癱瘓。
簡單模式。如果您使用此外掛的建議方式,「超級快取」檔案可以透由 PHP 提供,且依然非常快速。此方法比較容易設定,因為不需要更改 .htaccess 檔案。但仍然需要使用自訂連結。在此快取模式下,您的頁面仍然可以保有部分動態內容。
WP-Cache 快取。主要用於快取已知的使用者、具有參數 URL 的網址和訂閱源。已知的使用者是已登入的使用者、留言過的訪客或應該顯示個別使用者資料的訪問者。這是最靈活的快取方法,稍微慢一點。如果超級快取被停用,此方法也可以快取未知的用戶訪問。您的頁面在此模式中也可以保有動態部分。此模式總是啟用的,但您可以分別停用已知使用者、具有參數 URL 或是訂閱源的快取。如果要僅使用 WP-Cache 快取,請在您的 wp-config.php 中設置常數「DISABLE_SUPERCACHE」為 1。

如果您不熟悉編輯 PHP 檔案,請使用簡單模式。它易於設定且非常快速。

建議設定

使用簡單的快取方式。
壓縮頁面。
不要為已知使用者快取頁面。
快取重建。
支援 CDN。
額外首頁檢查。

垃圾回收是清理過期或久未使用的快取檔案。沒有正確的過期時間,但建議起點是1800秒。

考慮刪除「拒絕的使用者代理人」文本框中的內容,讓搜索引擎為您快取檔案。

預載盡可能多的文章,並啟用「預載模式」。此時舊的快取檔案將會被保留,不會進行垃圾清理。如果您不在意側邊欄小工具經常更新,請設置預加載間隔為2880分鐘(2天),以免您的所有文章被太頻繁地重新快取。當預先載入時,將刪除重新刷新的文章的快取檔案,然後再執行所有舊檔案的垃圾清理,以清除過期的快取檔案。
即使啟用預載模式,當文章被修改或留言時,仍會刪除快取檔案。

開發

A

原文外掛簡介

This plugin generates static html files from your dynamic WordPress blog. After a html file is generated your webserver will serve that file instead of processing the comparatively heavier and more expensive WordPress PHP scripts.
The static html files will be served to the vast majority of your users:

Users who are not logged in.
Users who have not left a comment on your blog.
Or users who have not viewed a password protected post.

99% of your visitors will be served static html files. One cached file can be served thousands of times. Other visitors will be served custom cached files tailored to their visit. If they are logged in, or have left comments those details will be displayed and cached for them.
The plugin serves cached files in 3 ways (ranked by speed):

Expert. The fastest method is by using Apache mod_rewrite (or whatever similar module your web server supports) to serve “supercached” static html files. This completely bypasses PHP and is extremely quick. If your server is hit by a deluge of traffic it is more likely to cope as the requests are “lighter”. This does require the Apache mod_rewrite module (which is probably installed if you have custom permalinks) and a modification of your .htaccess file which is risky and may take down your site if modified incorrectly.
Simple. Supercached static files can be served by PHP and this is the recommended way of using the plugin. The plugin will serve a “supercached” file if it exists and it’s almost as fast as the mod_rewrite method. It’s easier to configure as the .htaccess file doesn’t need to be changed. You still need a custom permalink. You can keep portions of your page dynamic in this caching mode.
WP-Cache caching. This is mainly used to cache pages for known users, URLs with parameters and feeds. Known users are logged in users, visitors who leave comments or those who should be shown custom per-user data. It’s the most flexible caching method and slightly slower. WP-Cache caching will also cache visits by unknown users if supercaching is disabled. You can have dynamic parts to your page in this mode too. This mode is always enabled but you can disable caching for known users, URLs with parameters, or feeds separately. Set the constant “DISABLE_SUPERCACHE” to 1 in your wp-config.php if you want to only use WP-Cache caching.

If you’re not comfortable with editing PHP files then use simple mode. It’s easy to set up and very fast.
Recommended Settings

Simple caching.
Compress pages.
Don’t cache pages for known users.
Cache rebuild.
CDN support.
Extra homepage checks.

Garbage collection is the act of cleaning up cache files that are out of date and stale. There’s no correct value for the expiry time but a good starting point is 1800 seconds.
Consider deleting the contents of the “Rejected User Agents” text box and allow search engines to cache files for you.
Preload as many posts as you can and enable “Preload Mode”. Garbage collection of old cached files will be disabled. If you don’t care about sidebar widgets updating often set the preload interval to 2880 minutes (2 days) so all your posts aren’t recached very often. When the preload occurs the cache files for the post being refreshed is deleted and then regenerated. Afterwards a garbage collection of all old files is performed to clean out stale cache files.
Even with preload mode enabled cached files will still be deleted when posts are modified or comments made.
Development

Active development of this plugin is handled on GitHub.
Translation of the plugin into different languages is on the translation page.

Documentation
If you need more information than the following, you can have a look at the wiki or the Developer documentation.
Preloading
You can generate cached files for the posts, categories and tags of your site by preloading. Preloading will visit each page of your site generating a cached page as it goes along, just like any other visitor to the site. Due to the sequential nature of this function, it can take some time to preload a complete site if there are many posts.
To make preloading more effective it can be useful to disable garbage collection so that older cache files are not deleted. This is done by enabling “Preload Mode” in the settings. Be aware however, that pages will go out of date eventually but that updates by submitting comments or editing posts will clear portions of the cache.
Garbage Collection
Your cache directory fills up over time, which takes up space on your server. If space is limited or billed by capacity, or if you worry that the cached pages of your site will go stale then garbage collection has to be done. Garbage collection happens on a regular basis and deletes old files in the cache directory. On the advanced settings page you can specify:
1. Cache timeout. How long cache files are considered fresh for. After this time they are stale and can be deleted.
2. Scheduler. Setup how often garbage collection should be done.
3. Notification emails. You can be informed on garbage collection job progress.
There’s no right or wrong settings for garbage collection. It depends on your own site.
If your site gets regular updates, or comments then set the timeout to 1800 seconds, and set the timer to 600 seconds.
If your site is mostly static you can disable garbage collection by entering 0 as the timeout, or use a really large timeout value.
The cache directory, usually wp-content/cache/ is only for temporary files. Do not ever put important files or symlinks to important files or directories in that directory. They will be deleted if the plugin has write access to them.
CDN
A Content Delivery Network (CDN) is usually a network of computers situated around the world that will serve the content of your website faster by using servers close to you. Static files like images, Javascript and CSS files can be served through these networks to speed up how fast your site loads. You can also create a “poor man’s CDN” by using a sub domain of your domain to serve static files too.
OSSDL CDN off-linker has been integrated into WP Super Cache to provide basic CDN support. It works by rewriting the URLs of files (excluding .php files) in wp-content and wp-includes on your server so they point at a different hostname. Many CDNs support origin pull. This means the CDN will download the file automatically from your server when it’s first requested, and will continue to serve it for a configurable length of time before downloading it again from your server.
Configure this on the “CDN” tab of the plugin settings page. This is an advanced technique and requires a basic understanding of how your webserver or CDNs work. Please be sure to clear the file cache after you configure the CDN.
REST API
There are now REST API endpoints for accessing the settings of this plugin. You’ll need to be authenticated as an admin user with permission to view the settings page to use it. This has not been documented yet but you can find all the code that deals with this in the “rest” directory.
Custom Caching
It is now possible to hook into the caching process using the add_cacheaction() function.
Three hooks are available:

‘wp_cache_get_cookies_values’ – modify the key used by WP Cache.
‘add_cacheaction’ – runs in phase2. Allows a plugin to add WordPress hooks.
‘cache_admin_page’ – runs in the admin page. Use it to modify that page, perhaps by adding new configuration options.

There is one regular WordPress filter too. Use the “do_createsupercache” filter
to customize the checks made before caching. The filter accepts one parameter.
The output of WP-Cache’s wp_cache_get_cookies_values() function.
WP Super Cache has its own plugin system. This code is loaded when WP Super Cache loads and can be used to change how caching is done. This is before most of WordPress loads so some functionality will not be available. Plugins can be located anywhere that PHP can load them. Add your own plugin either:

by putting your plugin in the wp-content/plugins/wp-super-cache-plugins directory, or
by calling wpsc_add_plugin( $name ) where $name is the full filename and path to the plugin. You only need to call that function once to add it. Use wpsc_delete_plugin( $name ) to remove it from the list of loaded plugins.

The cookies WP Super Cache uses to identify “known users” can be modified now by adding the names of those cookies to a list in the plugin configuration. Use wpsc_add_cookie( $name ) to add a new cookie, and wpsc_delete_cookie( $name ) to remove it. The cookie names also modify the mod_rewrite rules used by the plugin but I recommend using Simple mode caching to avoid complications with updating the .htaccess file.
The cookie name and value are used to differenciate users so you can have one cookie, but different values for each type of user on your site for example. They’ll be served different cache files.
See plugins/searchengine.php as an example I use for my No Adverts for Friends plugin.
Troubleshooting
If things don’t work when you installed the plugin here are a few things to check:

Is wp-content writable by the web server?
Is there a wp-content/wp-cache-config.php ? If not, copy the file wp-super-cache/wp-cache-config-sample.php to wp-content/wp-cache-config.php and make sure WPCACHEHOME points at the right place.
Is there a wp-content/advanced-cache.php ? If not, then you must copy wp-super-cache/advanced-cache.php into wp-content/. You must edit the file and change the path so it points at the wp-super-cache folder.
If pages are not cached at all, remove wp-content/advanced-cache.php and recreate it, following the advice above.

Make sure the following line is in wp-config.php and it is ABOVE the “require_once(ABSPATH.’wp-settings.php’);” line:
define( 'WP_CACHE', true );

Try the Settings->WP Super Cache page again and enable cache.
Look in wp-content/cache/supercache/. Are there directories and files there?
Anything in your php error_log?
If your browser keeps asking you to save the file after the super cache is installed you must disable Super Cache compression. Go to the Settings->WP Super Cache page and disable it there.
The plugin does not work very well when PHP’s safe mode is active. This must be disabled by your administrator.
If pages are randomly super cached and sometimes not, your blog can probably be viewed with and without the “www” prefix on the URL. You should choose one way and install the Enforce www preference plugin if you are using an old WordPress install. The latest versions redirect themselves (you should always be running the latest version of WordPress anyway!)
Private Server users at Dreamhost should edit wp-content/wp-cache-config.php and set the cache dir to “/tmp/” if they are getting errors about increasing CPU usage. See this discussion for more.
File locking errors such as “failed to acquire key 0x152b: Permission denied in…” or “Page not cached by WP Super Cache. Could not get mutex lock.” are a sign that you may have to use file locking. Edit wp-content/wp-cache-config.php and uncomment “$use_flock = true” or set $sem_id to a different value. You can also disable file locking from the Admin screen as a last resort.
Make sure cache/wp_cache_mutex.lock is writable by the web server if using coarse file locking.
The cache folder cannot be put on an NFS or Samba or NAS share. It has to be on a local disk. File locking and deleting expired files will not work properly unless the cache folder is on the local machine.

Garbage collection of old cache files won’t work if WordPress can’t find wp-cron.php. If your hostname resolves to 127.0.0.1 it could be preventing the garbage collection from working. Check your access_logs for wp-cron.php entries. Do they return a 404 (file not found) or 200 code? If it’s 404 or you don’t see wp-cron.php anywhere WordPress may be looking for that script in the wrong place. You should speak to your server administator to correct this or edit /etc/hosts on Unix servers and remove the following line. Your hostname must resolve to the external IP address other servers on the network/Internet use. See http://yoast.com/wp-cron-issues/ for more. A line like “127.0.0.1 localhost localhost.localdomain” is ok.
127.0.0.1 example.com

If old pages are being served to your visitors via the supercache, you may be missing Apache modules (or their equivalents if you don’t use Apache). 3 modules are required: mod_mime, mod_headers and mod_expires. The last two are especially important for making sure browsers load new versions of existing pages on your site.
The error message, “WP Super Cache is installed but broken. The path to wp-cache-phase1.php in wp-content/advanced-cache.php must be fixed!” appears at the end of every page. Open the file wp-content/advanced-cache.php in your favourite editor. Is the path to wp-cache-phase1.php correct? This file will normally be in wp-content/plugins/wp-super-cache/. If it is not correct the caching engine will not load.
Caching doesn’t work. The timestamp on my blog keeps changing when I reload. Check that the path in your .htaccess rules matches where the supercache directory is. You may have to hardcode it. Try disabling supercache mode.

If supercache cache files are generated but not served, check the permissions on all your wp-content/cache/supercache folders (and each of wp-content cache and supercache folders) and wp-content/cache/.htaccess. If your PHP runs as a different user to Apache and permissions are strict Apache may not be able to read the PHP generated cache files. To fix you must add the following line to your wp-config.php (Add it above the WP_CACHE define.) Then clear your cache.
umask( 0022 );

If you see garbage in your browser after enabling compression in the plugin, compression may already be enabled in your web server. In Apache you must disable mod_deflate, or in PHP zlib compression may be enabled. You can disable that in three ways. If you have root access, edit your php.ini and find the zlib.output_compression setting and make sure it’s “Off” or add this line to your .htaccess:
php_flag zlib.output_compression off

If that doesn’t work, add this line to your wp-config.php:
ini_set('zlib.output_compression', 0);

The “white screen of death” or a blank page when you visit your site is almost always caused by a PHP error but it may also be caused by APC. Disable that PHP extension if you have trouble and replace with eAccelerator or Xcache.
After uninstalling, your permalinks may break if you remove the WordPress mod_rewrite rules too. Regenerate those rules by visiting the Settings->Permalink page and saving that form again.
If your blog refuses to load make sure your wp-config.php is correct. Are you missing an opening or closing PHP tag?
Your front …

各版本下載點

  • 方法一:點下方版本號的連結下載 ZIP 檔案後,登入網站後台左側選單「外掛」的「安裝外掛」,然後選擇上方的「上傳外掛」,把下載回去的 ZIP 外掛打包檔案上傳上去安裝與啟用。
  • 方法二:透過「安裝外掛」的畫面右方搜尋功能,搜尋外掛名稱「WP Super Cache」來進行安裝。

(建議使用方法二,確保安裝的版本符合當前運作的 WordPress 環境。


0.1 | 0.2 | 0.3 | 0.4 | 0.5 | 0.7 | 0.8 | 0.9 | 1.0 | 1.1 | 1.2 | 1.3 | 1.4 | 1.8 | 1.9 | 0.3.1 | 0.5.1 | 0.5.2 | 0.5.3 | 0.6.2 | 0.6.3 | 0.6.4 | 0.6.5 | 0.6.6 | 0.6.7 | 0.6.8 | 0.7.1 | 0.8.1 | 0.8.2 | 0.8.3 | 0.8.4 | 0.8.5 | 0.8.6 | 0.8.7 | 0.8.8 | 0.8.9 | 0.9.1 | 0.9.2 | 0.9.3 | 0.9.4 | 0.9.5 | 0.9.6 | 0.9.7 | 0.9.8 | 0.9.9 | 1.0.1 | 1.1.1 | 1.2.1 | 1.3.1 | 1.3.2 | 1.3.3 | 1.4.1 | 1.4.2 | 1.4.3 | 1.4.4 | 1.4.5 | 1.4.6 | 1.4.7 | 1.4.8 | 1.4.9 | 1.5.0 | 1.5.1 | 1.5.2 | 1.5.3 | 1.5.4 | 1.5.5 | 1.5.6 | 1.5.7 | 1.5.8 | 1.5.9 | 1.6.0 | 1.6.1 | 1.6.2 | 1.6.3 | 1.6.4 | 1.6.5 | 1.6.6 | 1.6.7 | 1.6.8 | 1.6.9 | 1.7.0 | 1.7.1 | 1.7.2 | 1.7.3 | 1.7.4 | 1.7.5 | 1.7.6 | 1.7.7 | 1.7.8 | 1.7.9 | 1.9.1 | 1.9.2 | 1.9.3 | 1.9.4 | 2.0.0 | 2.0.1 | trunk | 1.10.0 | 1.11.0 | 1.12.0 | 1.12.1 | 1.12.2 | 1.12.3 | 1.12.4 | 0.9.3.1 | 0.9.4.1 | 0.9.4.2 | 0.9.4.3 | 0.9.6.1 | 0.9.9.1 | 0.9.9.2 | 0.9.9.3 | 0.9.9.4 | 0.9.9.5 | 0.9.9.6 | 0.9.9.7 | 0.9.9.8 | 0.9.9.9 | 1.5.7.1 | 1.9.2-beta | 1.9.3-beta | 1.9.4-beta | 1.10.0-beta | 1.9.2-beta2 | 1.9.2-beta3 |

延伸相關外掛(你可能也想知道)

  • Breeze – WordPress Cache Plugin 》Breeze是由Cloudways團隊開發的一款免費、簡單(卻功能強大)且使用者友好的WordPress快取外掛。它提供不同層級的WordPress效能優化選項,在WordPress、搭配W...。
  • DB Cache Reloaded Fix 》這個外掛可以緩存給定生命週期的每個資料庫查詢。它比其他 HTML 緩存外掛更快,並且對緩存使用較少的磁片空間。現在與 WordPress 3.1 兼容。, 這個外掛基於 s...。
  • WP-Cache.com 》WP-Cache.com 是最簡單、最快速的 WordPress 快取外掛程式。 WP-Cache.com 無縫運作!, 這個專案在 Github 上維護。, 這個外掛程式最初由 Jason Jersey (@deg...。
  • Uncache Script 》Uncache Script 是一個小型外掛,可在您編輯完樣式和腳本後取消它們的快取,因此它們不會在您的 WordPress 網站保留任何快取 🙂, 功能:, , 取消所有腳本和樣...。
  • Serve Static – Automatic WordPress Static Page generator 》總結:Serve Static 提供了在 WordPress 中實現靜態頁面緩存的高效、簡單和快速的方法。使用這個外掛可以生成靜態 HTML 的網頁副本,並通過服務器重寫規則進...。
  • WP Nav Menu Cache 》「WP Nav Menu Cache」外掛可協助您將 WordPress 動態導覽選單轉換為靜態導覽選單。每當訪客存取您的網站時,WordPress 會執行一些 MySQL 查詢及複雜的 PHP ...。
  • Really Static 》Really-Static 可以將您的部落格生成靜態 HTML 網頁。每當發布/編輯/刪除文章或留言時,更改將自動寫入靜態部落格中。, 如果您遇到問題、有漏洞資訊或有想法...。
  • Dessky Cache 》Dessky Cache 是 WordPress 的超輕型快取外掛,透過生成靜態 HTML 檔案並將其存儲在伺服器的磁碟上,讓您的網站運作更快。 Web 伺服器將傳遞靜態 HTML 檔案,...。
  • Flash Cache 》Flash Cache 是一個強大的外掛程式,透過處理和技術來減輕所安裝的網站的負荷,提高了網站速度,與其他 WordPress 快取外掛比較,可以達到最高 10 倍的效能改...。
  • WPMK Cache 》WPMK Cache 是最簡單也是最快速的 WordPress 快取外掛。它是一個輕量級的外掛,您只需要安裝並啟用其簡單選項,它就會自動運作。它能夠幫助您進行SEO優化。。
  • WP Offline Browser 》這是其中一款最優秀的外掛,能夠建立離線緩存,提升WordPress網站的載入速度和效能。。
  • Speed Clean Cache 》總結:這是一個簡單的 WordPress 外掛,可以清理 WordPress 快取、清除暫存記憶體、清除過期的臨時記憶體,以及優化資料庫。, , 問題與答案:, 1. 這個 WordP...。
  • {eac}ObjectCache – a persistent object cache using a SQLite database to cache WordPress objects.
    ,

    對象快取外掛介紹

    ,

    {eac}Doojigger Object Cache ({eac}ObjectCache) 是一個輕量且非常高效的持久...。

文章
Filter
Mastodon