問題描述

我正在 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(#替換為 @) 。