In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article mainly explains "Introduction to Several Methods of Smarty Local Cache". The explanation content in this article is simple and clear, easy to learn and understand. Please follow the ideas of Xiaobian to study and learn "Introduction to Several Methods of Smarty Local Cache" together.
Many times when we use smarty, we don't want to cache the entire page, such as weather, stocks and other information that is updated in real time. Then we can make it not cached. There are three common ways to implement it:
1. insert method:
The Insert function is similar to the inluce function, except that the contents of the insert are not cached and the function is re-executed each time the template is called. For example, we define a function that displays time:
The copy code is as follows:
function insert_get_current_time() {
return date("H:i:s");
}
//Then in the template:
{insert name="get_current_time"}
This way, every time you open a page, it shows the instant time, not the cached time. Note that the function name here must start with insert, and the name in the template corresponds to it. If our function contains some parameters, then our template can look like this:
The copy code is as follows:
{insert name="get_current_time" lid=#banner_location_id# sid=#site_id#}
//then Smarty calls this function like insert_get_current_time(array("lid"=>"12345","sid"=>67890"));
And display the returned result at the location of the call.
2. Dynamic block method:
In smarty code:
The copy code is as follows:
function smarty_block_nocache($param,$content,$smarty)
{
return $content;
}
$smarty->register_block('nocache','smarty_block_nocache',false);
In the template file:
The copy code is as follows:
//This is where you put content that doesn't need to be cached
3. Plug-in block method:
This is similar to block, but we do it in plug-in form. Create a file in the Smarty/plugins directory: block.nocache.php, where the name must be standardized, otherwise smarty will not recognize it. It reads as follows:
The copy code is as follows:
function smarty_block_nocache($param,$content,$smarty)
{
return $content;
}
In the template and above has been, do not need to be cached places with nocache can be!
Thank you for reading, the above is "Smarty local cache several methods of introduction" content, after the study of this article, I believe that we have a deeper understanding of Smarty local cache several methods of introduction this problem, the specific use of the situation also needs to be verified by practice. Here is, Xiaobian will push more articles related to knowledge points for everyone, welcome to pay attention!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.