問題描述
我正在 WordPress 中建立一個 Digg 的網站。
在安裝 W3 Total Cache 之後,我發現某些元素如每個帖子的投票數 (和投票 ids) 被快取,即使它們不應該是 (至少不是在使用者投票的文章之後) 。我認為不可能阻止某個頁面中的特定元素被快取 (或者是否)?所以我想到以程式設計方式觸發頁面快取重新整理。
有什麼建議麼?
最佳解決方案
如果你想重新整理快取,你可以這樣做:外掛有這個功能
<?php
flush_pgcache() //page cache
flush_dbcache() // database cache
flush_minify() // minify cache
flush_all() //all caches
?>
你只需要這樣呼叫它:
<?php
$w3_plugin_totalcache->flush_all();
?>
這基本上是題目 「快取重新整理程式設計方式」 的問題的答案
次佳解決方案
W3 Total Cache 支援片段快取。從常見問題解答
How do I implement fragment caching?
Edit your templates to with the following syntax to ensure that dynamic features remain so:
Example 1:
<!-- mfunc any PHP code --><!-- /mfunc -->
Example 2:
<!-- mfunc -->any PHP code<!-- /mfunc -->
Example 3:
<!--MFUNC -->
echo rand();
<!--/mfunc -->
Example 4:
<!-- mclude path/to/file.php --><!-- /mclude -->
Example 5:
<!-- mclude -->path/to/file.php<!-- /mclude -->
第三種解決方案
Bainternet 的解決方案似乎不適合我。
我在外掛中成功地使用了這個替代程式碼片段,並在 admin_init 操作中載入:
// Clear all W3 Total Cache
if( class_exists('W3_Plugin_TotalCacheAdmin') )
{
$plugin_totalcacheadmin = & w3_instance('W3_Plugin_TotalCacheAdmin');
$plugin_totalcacheadmin->flush_all();
echo __('<div class="updated"><p>All <strong>W3 Total Cache</strong> caches successfully emptied.</p></div>');
}
希望這有助於某人在那裡。
第四種方案
要在 w3tc v0.9.3 中透過 post id 重新整理單個頁面,我發現這個工作:
if (function_exists('w3tc_pgcache_flush_post')){
w3tc_pgcache_flush_post($post_id);
}
第五種方案
以上這些都不適合我的外掛。但是這樣工作!確認為 w3tc 版本 0.9.2.4 。
if (function_exists('w3tc_dbcache_flush')) { w3tc_dbcache_flush(); }
我做了一個 「$ wpdb-> get_results(」sb_settings f_fb_app_id sb_settings sb_settings f_fb_secret sb_settings「); 並且令人驚訝的是,值 f_fb_secret 和 f_fb_app_id 是相同的每次。顯然 w3tc 快取查詢的結果。所以我在 sb_settings 表的修改頁面中新增了一個 dbcache flush 。
如果要清除頁面快取,那麼只需使用 w3tc_pgcache_flush 。
參考文獻
注:本文內容整合自 google/baidu/bing 翻譯的英文資料結果。如果您對結果不滿意,可以加入我們改善翻譯效果:gxnotes#qq.com(#替換為 @) 。