: This article mainly introduces php-Smarty-cache 2 (26). If you are interested in the PHP Tutorial, refer to it. On a page, some data is cached, and some data is not cached, that is, local cache.
L $ smarty-> assign ("var", "value", true)
Third parameter: indicates whether the cache is not cached
L {$ var nocache = true}
Use the nocache parameter after the template variable quantity
L {nocache} {/nocache}
Use a nocache flag, so that all content between them is not cached.
Cached file: We found that the name is directly written to the file, and the age needs to be dynamically read each time to implement the local cache function.
Try to modify the value of name and age. Note that the variable, name, and age on the page remain unchanged.
7. Multiple cache operations on a single page
Http: // localhost/news. php? Id = 100
View News with id 100
After the access, a cache file is generated for this template, and the news with id 100 is cached.
Http: // localhost/news. php? Id = 80
View News with id 80
At this time, we will see the previous cached file
L $ smarty-> caching = true
Enable caching
L $ smarty-> display ("tpl", "cacheid ")
The second parameter indicates the cache ID, which is the unique standard of a cache file.
Code:
We use the following URLs to access them:
Demo07.php? Id = 10
Demo07.php? Id = 83
Demo07.php? Id = 96
Then, the following cache files are generated in the cache Directory:
The content before the file name ^ Is the cache ID, which is the unique identifier of the cache file.
What should I do when clearing cached files?
$ Smarty-> abstrache('demo07.html ');
This indicates that all cached files in the demo07 template are cleared.
$ Smarty-> abstrache('demo07.html ', 83)
This indicates that the cache file with the ID 83 corresponding to the demo07 template is deleted.
8. cache set
Http: // localhost/news. php? Kid = 10 & page = 8
This indicates that you want to view the news title with the news category id 10 and display the data on the 8th page. how can this problem be cached?
L $ smarty-> caching = true
Enable cache
L $ smarty-> display ("tpl", $ id1. "|". $ id2)
Sets the cache ID and uses | for connection, indicating a cache set.
Code:
Run the following url:
Deo08.php? Kid = 13 & page = 2
Deo08.php? Kid = 25 & page = 8
Deo08.php? Kid = 2 & page = 58
It is found that several cached files are generated under the cache directory.
In fact, it means to use | to connect all the obtained parameters to generate a new cache file.
Apply Smarty in MVC
I. MVC
1. M: Model
2. V: View
3. C: Controller
We need to replace our previous View component with Smarty.
The above introduces php-Smarty-cache 2 (26), including some content, and hope to be helpful to friends who are interested in PHP tutorials.