我正在尝试将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;
?>我不知道如何用我的页面替换“渲染你的页面”。我尝试过"include","get_file_content"...None的工作。
谁能给我举个例子?
谢谢
发布于 2013-07-30 06:29:59
要获得在调用原始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)似乎没有任何可以使用的内置函数。
https://stackoverflow.com/questions/17934941
复制相似问题