- $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
Copy CodeSecond, the use and elimination of Smarty cache
- $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
Copy CodeThird, Smarty local cache first: The Insert_ function is not cached by default, this property cannot be modified using the method: Example index.php,
- function Insert_get_time () {
- Return Date ("y-m-d h:m:s");
- }
Copy CodeIn Index.html,
- {Insert Name= "Get_time"}
Copy CodeThe second: Smarty_block defines a block:smarty_block_name ($params, $content, & $smarty) {return $content;}//name represents the zone domain name registration block: $smarty->register_block (' name ', ' Smarty_block_name ', false); The third parameter, False, indicates that the zone is not scripted by the cached template: {name} content {/name} is written as a block plugin: 1) defines a plug-in function: block.cacheless.php, The contents of the plugins directory block.cacheless.php placed in Smarty are as follows:
- function smarty_block_cacheless ($param, $content, & $smarty) {
- return $content;
- }
- ?>
Copy Code2) Writing Program and Template sample program: testcacheless.php
- Include (' Smarty.class.php ');
- $smarty = new Smarty;
- $smarty->caching=true;
- $smarty->cache_lifetime = 6;
- $smarty->display (' Cache.tpl ');
- ?>
Copy CodeTemplate used: Cache.tpl already cached: {$smarty. Now} {cacheless} is not cached: {$smarty. now}{/cacheless} Four, custom cache settings Cache_handler_func use a custom function to handle the cache such as:
- $smarty->cache_handler_func = "Mycache";
- function Mycache ($action, & $smarty _obj, & $cache _content, $tpl _file=null, $cache _id=null, $compile _id=null) {
- }
Copy CodeThe 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
- }
Copy CodeGeneral use of MD5 ($TPL _file. $cache _id. $compile _id) as the only cache_id if required, use gzcompress and gzuncompress to compress and decompress. |