4

What makes smarty decide if the cache it has is sufficient or if it needs to recreate it? Will the $_REQUEST do? Or all globals including cookies, session and etc... Is index.php and index.php?task=home have the same cache, what about cookies and session info? How does it work? I have a site that I want to cache to the maximum potential but I don't even know how the cache works and they don't explain the internals on the smarty website.

Answer To Rodney that might be helpful in understanding my question: I'm interested in knowing if smarty turns dynamic code into static html as in: smarty.net/docs/en/language.function.nocache.tpl and if so when and how does it decide that the cache is good or bad. so if I had Hello {$user->username}! would it show the Hello Rodney To Brad because it cached it when brad was looking at the page?

Neo
  • 11,078
  • 2
  • 68
  • 79
  • 1
    Neo, I apologize for my incorrect answer. Learn something new every day! I have deleted it. – Brad Feb 10 '12 at 14:45

1 Answers1

3

read the docs on Caching.

Smarty decides to re-execute a template if a cache cannot be found, or has exceeded its lifetime. $cache_id is a value one passes smarty to make it save the cache specifically for $cache_id

UPDATE

The section Controlling Cacheability of Output explains how smarty can handle dynamic content within static caches. That page answers your question regarding "Rodney" and "Brad" being dynamic values injected into the cached rendering of the template.

rodneyrehm
  • 13,442
  • 1
  • 40
  • 56
  • how does this answer my question I have already read this page. I'm interested in knowing if smarty turns dynamic code into static html as in: smarty.net/docs/en/language.function.nocache.tpl and if so when and how does it decide that the cache is good or bad. so if I had Hello {$user->username}! would it show the Hello Rodney To Brad because it cached it when brad was looking at the page? – Neo Feb 10 '12 at 09:28
  • so you are saying I should decide that and use cache_id otherwise smarty has no smart way of doing this like making a hash our of global variable changes? – Neo Feb 10 '12 at 09:31
  • Smarty will not infer any cache validity from the content you passed in. Smarty will ONLY check the modification time of the output-cache-file (in $cache_dir), the modification time of the compiled template (in $compile_dir) and the modification time of the source template (in $template_dir). – rodneyrehm Feb 10 '12 at 09:43
  • thanks this is very helpful I guess I just have to keep the cache problem in mind when I am programming I was thinking of using all the variables that can make a page different and create a hash our of them and use them as the $cache_id. It seems like to smarty index.php?page=home and index.php?page=admin are the same thing? – Neo Feb 10 '12 at 13:37
  • +1 I am not going to select an answer for a couple days to get more ideas. – Neo Feb 10 '12 at 13:38
  • 1
    Caching a specific for every user you've got is a very bad idea. For one, the cache has to be generated for each user (so why cache at all?) - and then you have $numberOfResources * $numberOfUser cache files on disk? – rodneyrehm Feb 10 '12 at 17:24
  • 1
    cache what's the same across different users and make the stuff that's user-dependent `{nocache}`. That way you have only one cache per resource… – rodneyrehm Feb 10 '12 at 17:25