1,smarty Cache Configuration:
$smarty->cache-dir= "directory name"; Create cache directory Name
$smarty->caching=true; Turn on cache, invalid cache for false
$smarty->cache_lifetime=60; Cache time, Unit is seconds
Use and purge of 2,smarty cache
$marty->display ("Cache.tpl", cache_id); To create a cache with IDs
$marty->clear_all_cache (); Clear all Cache
$marty->clear_cache ("index.php"); Clear the cache in index.php
$marty->clear_cache ("index.php ', cache_id);" Clear cache of specified IDs in index.php
Local cache of 3,smarty
First: The Insert_ function is not cached by default, this property is not 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
Define a Block:smarty_block_name ($params, $content, & $smarty) {return $content;}//name the domain name of the zone
Register BLOCK: $smarty->register_block (' name ', ' Smarty_block_name ', false); The third argument false indicates that the range is not cached
Template notation: {name} content {/name}
Write 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:
<?php
function smarty_block_cacheless ($param, $content, & $smarty) {
return $content;
}
?>
2 Writing programs and templates
Sample program: testcacheless.php
Copy Code code as follows:
<?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}<br>
{cacheless}
Not cached: {$smarty. Now}
{/cacheless}
4 Custom Caching
Set Cache_handler_func to process caching using custom functions
Such as:
$smarty->cache_handler_func = "Mycache";
function Mycache ($action, & $smarty _obj, & $cache _content, $tpl _file=null, $cache _id=null, $compile _id=null) {
}
This function is generally rooted in the $action to determine the current operation of the cache:
Switch ($action) {
Case "read"://Read cache content
Case "Write"://write Cache
Case "clear"://Empty
}
General use of MD5 ($TPL _file. $cache _id. $compile _id) as the only cache_id
If necessary, use gzcompress and gzuncompress to compress and decompress