Configuration of the 1,smarty cache:
Copy the Code code as follows:
$smarty->cache-dir= "directory name"; Create a cache directory name
$smarty->caching=true; Cache is turned on, false when caching is not valid
$smarty->cache_lifetime=60; Cache time in seconds
Use and purge of 2,smarty cache
Copy the Code code as follows:
$marty->display ("Cache.tpl", cache_id); Create a cache with ID
$marty->clear_all_cache (); Clear all Caches
$marty->clear_cache ("index.php"); Clear the cache in index.php
$marty->clear_cache ("index.php", cache_id); Clear cache of the specified ID in index.php
Local cache for 3,smarty
The first: The Insert_ function is not cached by default, and this property cannot be modified
How to use: Example
In index.php,
function Insert_get_time () {
Return Date ("y-m-d h:m:s");
}
In Index.html,
{Insert Name= "Get_time"}
The second one: Smarty_block
Defines a block:smarty_block_name ($params, $content, & $smarty) {return $content;}//name represents the domain name of the zone
Register BLOCK: $smarty->register_block (' name ', ' Smarty_block_name ', false); The third parameter, False, indicates that the zone is not cached
Template notation: {name} content {/name}
Written as Block plugin:
1) Define a plug-in function: block.cacheless.php, placed in the Smarty plugins directory
The contents of block.cacheless.php are as follows:
function smarty_block_cacheless ($param, $content, & $smarty) {
return $content;
}
?>
2) Writing Programs and templates
Example program: testcacheless.php
Include (' Smarty.class.php ');
$smarty = new Smarty;
$smarty->caching=true;
$smarty->cache_lifetime = 6;
$smarty->display (' Cache.tpl ');
?>
Template used: CACHE.TPL
Already cached: {$smarty. Now}
{cacheless}
Not cached: {$smarty. Now}
{/cacheless}
4 Custom Cache
Set Cache_handler_func to handle caching using a custom function
Such as:
$smarty->cache_handler_func = "Mycache";
function Mycache ($action, & $smarty _obj, & $cache _content, $tpl _file=null, $cache _id=null, $compile _id=null) {
}
The function is generally rooted in the $action to determine the current operation of the cache:
Switch ($action) {
Case "read"://Read Cache contents
Case "Write"://write Cache
Case "clear"://Empty
}
General use of MD5 ($TPL _file. $cache _id. $compile _id) as the only cache_id
If required, use gzcompress and gzuncompress to compress and decompress
The above describes a cache application in the ESET Smart Security php smarty template engine, including content from ESET Smart Security, which hopefully helps friends interested in PHP tutorials.