I have a template which is of .php extension.
This template contains the html maarkup along with some php variables. This is how it looks like.
include_once VIEWDIR . 'documentation/common/header.php';
include_once VIEWDIR . 'documentation/content/'.$this->view.'.php';
include_once VIEWDIR . 'documentation/common/leftsidebar.php';
include_once VIEWDIR . 'documentation/common/rightsidebar.php';
This is the way i am caching.
ob_start();
include_once('template.php');
$templateCache = ob_get_clean();
Then i store this in a .cache file.
The problem is when i load the template from cache, it is not able to read the php variables.
I know i am doing something wrong but not able to catch it. Please help.
Caching in general
Caching, by definition, caches the values of the respective variables.
What you want to do is to delete the cache when one of the variables used in the template changes its value.
This way, the cache will get regenerated, with the new values, and you’ll have the advantages of both worlds:
Caching in your case
Disclaimer: This does not necessarily uses your problem as a showcase. You should improve your question if you need a more to-the-point answer.
If your template has some areas that change often, and some that don’t, then you should cache separately only those portions that do not change often, and leave the overall template which contains the changing variables uncached as a whole.
Do not forget to treat individual caches as described above to have a proper behavior of the system.
So instead of caching the whole file, you rewrite it as something like this:
and you treat the individual parts of the template as caches themselves.