php-smarty-Cache 2 (26)
A page, some data cache, some data is not cached, is the local cache
L $smarty->assign ("var", "value", true)
Third parameter: Indicates whether to not cache
L {$var Nocache=true}
Use the NoCache parameter after the template variable amount
l {Nocache}{/nocache}
Using a pair of NoCache tags, all content between them is not cached
Cache files: We find that names are written directly to the file, and the age needs to be read dynamically each time to implement the local cache function
Try to modify the value of name and age, note the variable that occurs on the page, name is unchanged, age changes
Seven, single-page multi-cache
http://localhost/news.php?id=100
View News with ID 100
Once accessed, a cache file is generated for this template, with the cached ID 100 News
Http://localhost/news.php?id=80
View News with ID 80
At this point, the previous cache file will be seen
L $smarty->caching=true
Turn on caching mechanism
L $smarty->display ("TPL", "CacheID")
The second parameter represents the cache ID, which is the only standard for a cache file
Code:
We use this URL to access:
demo07.php?id=10
demo07.php?id=83
demo07.php?id=96
Then, found in the cache directory, produce such a few cache files:
The content before the file name ^ is the cache ID, which is the unique identifier of the cache file.
What do I do when I clear the cache file?
$smarty->clearcache (' demo07.html ');
This writes to erase all cached files of the demo07 template
$smarty->clearcache (' demo07.html ', 83)
This writes to delete the cache file with the ID 83 corresponding to the demo07 template
Viii. Collection of Caches
Http://localhost/news.php?kid=10&page=8
Would you like to see a news headline with a news category ID of 10, and show the data on page 8th, how do I cache it?
L $smarty->caching=true
Turn on the cache function
L $smarty->display ("TPL", $id 1. "|". $id 2)
Set the cache ID and use | To make a connection, indicating that it is a cache collection
Code:
Run the following URL:
deo08.php?kid=13&page=2
Deo08.php?kid=25&page=8
deo08.php?kid=2&page=58
Found, in the cache directory, to produce such a few cache files
In fact, it means all the parameters that will be given | Connect, generate a new cache file
Applying Smarty in MVC
First, MVC
1, M: Model
2, V: View
3, C: Controller
is to replace our previous view component with Smarty.