Reputation: 4598
I have a Template Parser function which loads the raw html code of the template with the given name and replaces wildcards in it (%DATE%,etc). I will be using the same template more than once for some pages, e.g. a menu item, and so the html file would be loaded into memory more than once.
So one file would be read more than once because the ParseTemplate(name)
function is called more than once with the same template.
For clarity: The same template is going to be loaded more than once in one page.
Is it worth storing all loaded template files in an array so they don't have to be read with file_get_contents();
more than once?
Upvotes: 0
Views: 149
Reputation: 25060
Well if you use the same template (snippet I guess) more than once in a single page, then yes save it in a variable and print it every time it's needed after the substitution of wildcards.
Upvotes: 1
Reputation: 798566
PHP variables only last for the time of the request unless you use shared memory. You'd need to base your method on how much memory you want to chew up with that instead of httpd processes or database cache.
Upvotes: 0