There are several ways to invalidate the cache in some areas (only for the desired cache):
First,Inser:
Defines a handler function to be used for a inser tag, with the format of the function name: insert_xx (array $params, Object & $smarty) where xx is the name of the insert, that is, if you define a function as Insert_ ABC, the method used in the template is {insert Name=abc}
Parameters passed through $params
can also be made into insert plug-in, file name named: insert.xx.php, Function named: Smarty_insert_aa ($params,& $smarty), xx definition ibid.
Second,Register_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}
Run it now and find that it's not working, and both lines are cached.
(3) Rewrite Smarty_Compiler.class.php (Note: This file is important, please back up first to restore if necessary)
Find $this->_plugins[block][$tag _command] = Array ($plugin _func, NULL, NULL, NULL, TRUE); //My Line in 705
Modified to:
if ($tag _command = = cacheless) $this->_plugins[block][$tag _command] = Array ($plugin _func, NULL, NULL, NULL, FALSE);
else $this->_plugins[block][$tag _command] = Array ($plugin _func, NULL, NULL, NULL, TRUE);
You can also directly change the last parameter of the original sentence to false, I do not understand the internal mechanism of smarty, so add a judgment, as long as the block is cacheless not cache
(4) OK, now clear the Template_c in the compilation file, re-run, it worked?
Source: Programming House
http://www.bkjia.com/ phpjc/486228.html www.bkjia.com true http://www.bkjia.com/phpjc/ 486228.html techarticle