Reputation: 33
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
Upvotes: 1
Views: 1957
Reputation: 1041
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.
Upvotes: 3