What about Template Caching?

Author Topic: What about Template Caching?  (Read 4667 times)

Offline chinmay.sahooTopic starter

  • Trade Count: (0)
  • Full Member
  • ***
  • Thank You 2
  • Posts: 158
  • Karma: 0
    • We Helpline
What about Template Caching?
« on: 07-21-2016, 05:56:29 »
Template engines such as Smarty[4] often talk about template caching. Usually, these engines offer an in-built mechanism for storing a compiled version of a template (i.e. the native PHP generated from the template), which prevents us having to recompile the template every time a page is requested. This should not be confused with output caching, which refers to the caching of the rendered HTML (or other output) that PHP sends to the browser. You can successfully use both types of caching together on the same site.

Here, we’ll look at PHP’s in-built caching mechanism, the output buffer[5], which can be used with whatever page rendering system you prefer (templates or no templates). Consider a situation in which your script displays results using, for example, echo or print, rather than sending the data directly to the browser. In these cases, you can use PHP’s output control functions to store the data in an in-memory buffer, which your PHP script has both access to and control over.

// Start buffering the output
// Echo some text (which is stored in the buffer);
echo '1. Place this in the buffer<br />';
// Get the contents of
$buffer = ob_get_contents();
// Stop buffering and clean out the buffer
// Echo some text normally
echo '2. A normal echo<br />';
// Echo the contents from the buffer
echo $buffer;

The buffer itself stores the output as a string. So, in the above script, we commence buffering with ob_start and use echo to display something. We then use ob_get_contents to fetch the data the echo statement placed in the buffer, and store it in a string. The ob_end_clean function stops the output buffer and trashesm the contents; the alternative is ob_end_flush, which displays the contents of the

Offline saravjeet

  • Trade Count: (0)
  • Semi-Newbie
  • *
  • Thank You 4
  • Posts: 39
  • Karma: 0
    • Ecommerce Website Builder
Re: What about Template Caching?
« Reply #1 on: 12-02-2016, 04:07:43 »
The first time a template is used, it is loaded in the template cache for quick retrieval. You can load templates directly into the cache in a script tag, or by consuming the $templateCache service directly.


Related Topics

  Subject / Started by Replies Last post
5 Replies
Last post 07-05-2013, 03:36:00
by webcreations
2 Replies
Last post 03-27-2014, 04:27:46
by rohitaddnectar
8 Replies
Last post 04-19-2016, 08:54:40
by ramakant.sharma24
11 Replies
Last post 09-03-2018, 23:10:35
by richardmsmith
1 Replies
Last post 05-03-2017, 00:53:40
by David910