2013-07-29 22 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