首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >将phpFastCache用于页面

将phpFastCache用于页面
EN

Stack Overflow用户
提问于 2013-07-30 05:57:17
回答 1查看 1.9K关注 0票数 1

我正在尝试将phpFastCache集成到我的应用程序中。

这是它在文档中所说的:

代码语言:javascript
复制
<?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的工作。

谁能给我举个例子?

谢谢

EN

回答 1

Stack Overflow用户

发布于 2013-07-30 06:29:59

要获得在调用原始PHP代码后发送到浏览器的生成内容,您需要使用输出缓冲区方法。

这就是如何在上面的示例中包含PHP文件并缓存结果以供将来的请求使用:

代码语言:javascript
复制
<?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)似乎没有任何可以使用的内置函数。

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/17934941

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档