1

I'm trying to integrate phpFastCache to my application.

This is what it said in the docs:

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

I didn't find how to replace "RENDER YOUR PAGE" by my page. I tried "include", "get_file_content"...None works.

Any one can give me an exemple please ?

Thank you

1 Answer 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.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks a lot, it works :) I'wd vote+1 for you but I don't have suffisant reputations to do it, sorry and thanks again :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.