Author Topic: How exactly does the vlib template caching work?  (Read 1980 times)

0 Members and 1 Guest are viewing this topic.

tribui

  • Guest
How exactly does the vlib template caching work?
on: Tue, 20. August 2002 - 20:47:22
Hi,

I am a little unclear how the caching works. If I have a php page that generates dynamic content based on the GET parameters, when I initialize the template w/caching:

$tmpl = new vlibTemplateCache('mytemplates/mytemplatefile.html', $options);

I specify a single filename for the cache file. So what exactly is cached? Is it the template file with expanded loop sections and placeholders?

If it is the complete HTML that will be outputted, how will this be effective if different parameters in the GET string sent to the php script will affect the output espicially since the next time the script is called, vlib will recognize there is a cache file existing and output it, irregardless of the GET values?

So is the caching system only useful if there are static pages that use a template?

Great work on vlib and I am migrating from another template system to yours and I would like to contribute to optimize the performance when I have some time.

Thanks,

tribui

releasedj

  • Guest
How exactly does the vlib template caching work?
Reply #1 on: Wed, 21. August 2002 - 12:42:17
Hi tribui,

vlibTemplate works by compiling your templates into native PHP code, i.e.:
Code: [Select]
tmpl_var name=myVar
.. becomes something like:
Code: [Select]
?php echo $this-_vars'myVar'; ?
(this isn't the exact string at all, just an example, the real thing is alot more complicated)

Now vlibTemplate uses PCRE to search for all TMPL_* tags and replaces them with the correct PHP representation. This 'compiled' code is then parsed to PHP's eval() function to let PHP do all the hard work.

Now if you use vlibTemplateCache, it will only need to compile the file once, it will then write the compiled code to a file which it can then use on subsequent request thus by-passing the PCRE call.

Therefore this does NOT cache the actual output of your code, just the compiled template.

If you use vlibTemplate without the caching fuctionality then the time taken to serve your pages depends very much so on how many <tmpl_* > tags you have in your template as it has to search for each one every time. However with vlibTemplateCache, you don't have to bother and you can therefore knock seconds (for real) off of the time taken to serve a page.

I hope this answers your question.

Kind regards,

Kelvin
PS: Any help with vLIB is greatly appreciated.