簡體   English   中英

php緩存動態索引頁面

[英]php cache dynamic index page

我找到了緩存MySQL結果的phpfastcahce類。 在支持WinCache,MemCache,文件,X-Cache,APC Cache的詳細信息中說:

PHP Caching Class For Database : Your website have 10,000 visitors who are online, and your dynamic page have to send 10,000 same queries to database on every page load. With phpFastCache, your page only send 1 query to DB, and use the cache to serve 9,999 other visitors.

在示例代碼中:

<?php
    // In your config file
    include("php_fast_cache.php");
    // This is Optional Config only. You can skip these lines.
    // phpFastCache support "apc", "memcache", "memcached", "wincache" ,"files", "pdo", "mpdo" and "xcache"
    // You don't need to change your code when you change your caching system. Or simple keep it auto
    phpFastCache::$storage = "auto";
    // End Optionals

    // In your Class, Functions, PHP Pages
    // try to get from Cache first.
    $products = phpFastCache::get("products_page");

    if($products == null) {
        $products = YOUR DB QUERIES || GET_PRODUCTS_FUNCTION;
        // set products in to cache in 600 seconds = 10 minutes
        phpFastCache::set("products_page",$products,600);
    }

    foreach($products as $product) {
        // Output Your Contents HERE
    }
?>

現在,在我的網站索引中,我有任何塊顯示最新消息,最佳新聞,世界新聞.....緩存我的索引,我必須緩存每個塊的MySQL結果(last news, best news, world news ..... )如果我編輯現有新聞或添加新消息,使用phpfastcache並在管理頁面中刪除所有緩存? 這是一種真實的方式嗎?

什么是最好的方法對於緩存MySQL結果我的索引頁面使用phpfastcache (任何方法)?!

phpfastcache無法理解您的數據是否已更改

在數據庫中更改特定數據后,您必須執行某些操作

首先在你的主頁緩存代碼必須是這樣的:

$lastnews = phpFastCache::get('index_lastnews');
$bestnews = phpFastCache::get('index_bestnews');
$worldnews = phpFastCache::get('index_worldnews');

if($lastnews == null) {
    $lastnews = YOUR DB QUERIES || GET_DATA_FUNCTION;
    phpFastCache::set('index_lastnews',$lastnews,600);
}
if($bestnews == null) {
    $bestnews = YOUR DB QUERIES || GET_DATA_FUNCTION;
    phpFastCache::set('index_bestnews',$bestnews,600);
}

並在您的管理頁面中,當特定數據更改緩存代碼必須如下所示:

AFTER DATABASE insert | update ....

您可以通過以下兩種方式替換舊緩存:

1)刪除緩存(刪除緩存后,首次訪問后緩存自動重建)

phpFastCache::delete('index_lastnews');

2)更新緩存

$lastnews =   YOUR DB QUERIES || GET_DATA_FUNCTION;
phpFastCache::set("index_lastnews",$lastnews,600);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM