I want to build a cache system for a e-commerce platform.
I’ve choosed to use ob_start('callback') and ob_end_flush() at the end of the page.
I will verify if there is any .cache file created for the visited url and if there is a file I will print its content out.
My problem is that I want to keep the shopping cart live so I don’t want to cache it. How can I achieve that?
<?php
function my_cache_function($content) {
return $content;
}
ob_start('my_cache_function');
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>test</title>
</head>
<body>
test
<?php
//some ob_break() ?
?>
<div id="shopping-cart">
this should be the content I do not want to cache it
</div>
<?php
// ob_continue() ?
?>
</body>
</html>
<?php
ob_end_flush();
?>
Thank you in advance!
If you do that, the problem is that content will output BEFORE any HTML placed before. What you may want is to save that content in some variable, then use a placeholder in your cache “template” file, like %SHOPPING-CART%
You can therefore replace it with a str_replace with the real non-cached content.