1

我正在尝试将 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;
?>

我没有找到如何用我的页面替换“RENDER YOUR PAGE”。我尝试了“include”、“get_file_content”...没有任何效果。

任何人都可以给我一个例子吗?

谢谢

4

1 回答 1

3

To get the generated content that is sent to the browser after invoking your original PHP code, you would need to use the output buffer methods.

This is how you would include a PHP file and cache the results for future requests in your example above:

<?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;
?>

Using the output buffer is a very common way of performing caching in PHP. It seems that the library you are using (phpFastCache) does not have any built-in functions that could be used instead.

于 2013-07-29T22:29:59.097 回答