2013-07-29 41 views
1

我試圖將phpFastCache集成到我的應用程序。使用phpFastCache頁面

這是它在文檔中說:

<?php 
    // try to get from Cache first. 
    $html = phpFastCache::get(array("files" => "keyword,page")); 

    if($html == null) { 
     $html = Render Your Page || Widget || "Hello World"; 
     phpFastCache::set(array("files" => "keyword,page"),$html); 
    } 

    echo $html; 
?> 

我沒有找到如何更換我的頁面「呈現您的網頁」。 我試過「包含」,「get_file_content」...沒有任何作用。

任何人都可以給我一個例子嗎?

謝謝

回答

3

要獲得被調用原來的PHP代碼後發送給瀏覽器所生成的內容,您將需要使用輸出緩衝方法。

這是你如何將PHP文件包含並緩存爲將來的請求的結果顯示在上面的例子:

<?php 
    // try to get from Cache first. 
    $html = phpFastCache::get(array("files" => "keyword,page")); 

    if($html == null) { 
     // Begin capturing output 
     ob_start(); 

     include('your-code-here.php'); // This is where you execute your PHP code 

     // Save the output for future caching 
     $html = ob_get_clean(); 

     phpFastCache::set(array("files" => "keyword,page"),$html); 
    } 

    echo $html; 
?> 

使用輸出緩存爲PHP執行高速緩存的一種很常見的方式。看來你正在使用的庫(phpFastCache)沒有任何內置函數可以用來代替。

+0

非常感謝,它的工作原理:) I'wd投+ 1你,但我再也沒有suffisant聲譽做,對不起和謝謝:) – Hdev