During the cache period, if the template file is modified, the program will re-read the template and generate the compilation file as the cache.
Process:
Set cache for the first time:
$ Smarty-> caching = 1;
$ Smarty-> cache_lifetime = 300; // Set cache for the first time
After compilation, a cache file will be generated in cache_dir, which contains the cache_lifetime when the cached file is generated, that is, 300 seconds;
Then modify
$ Smarty-> caching = 2;
$ Smarty-> cache_lifetime = 5; // sets the cache for the second time.
After changing some content, compile it again. if you only check cache_lifetime, the changed content will take effect in 5 seconds, but the fact is that it takes 300 seconds, because caching is equal to 2, the cache time is calculated based on the cache_lifetime (300 seconds) in the current cache_dir cache file, instead of the set 5 seconds. The second set cache_lifetime (5 seconds) is recorded in the cache file until the cache is updated again.
If the cache is set for the second time:
$ Smarty-> caching = 1;
$ Smarty-> cache_lifetime = 5; // sets the cache for the second time.
The changed content takes effect in 5 seconds.
When smarty enables static cache, html static pages are generated. at this time, no-logic can be executed, as long as the system first determines whether a cache is generated, and if yes, it can be output directly, and then the script is stopped directly, this is very efficient, which is equivalent to directly opening a static page,
When static cache is not enabled, a template compilation file will be generated to convert all smarty labels into echo variables, which cannot improve any efficiency, but it does not increase the execution time too much,
"Smarty uses a caching technology that caches the final HTML file you see into a static HTML page. when the cache attribute of smarty is set to true, during the cachetime period set by smarty, user WEB requests are directly converted to this static HTML file, which is equivalent to calling a static HTML file."
"Smarty does not directly generate html static page files. The smarty cache still reads php files, but only caches the template execution results"
If cache caching = false is not enabled, during the first execution, the compilation file under tmeplates_c is generated. if the template file under tmplates is not changed for the next access, the database is updated, the program will also directly access the compilation file (the compilation file is also a php file)
If cache caching = true is enabled and cache_lifetime is used within the cache period, the program directly accesses the cached html file even if the database is updated without modifying the template file. After the cache period expires, the program accesses the compiled file to generate a new cache,
During the cache period, if the template file is modified, the program will re-read the template and generate the compilation file as the cache.