Smarty核心内容:Caching [缓存]
来源:互联网 发布:php开源论坛 wap 编辑:程序博客网 时间:2024/05/17 17:39
Caching [缓存]
Setting Up Caching [建立缓存]
require('Smarty.class.php');$smarty = new Smarty;$smarty->caching = 2; // lifetime is per cache// set the cache_lifetime for index.tpl to 5 minutes$smarty->cache_lifetime = 300;$smarty->display('index.tpl');// set the cache_lifetime for home.tpl to 1 hour$smarty->cache_lifetime = 3600;$smarty->display('home.tpl');
// NOTE: the following $cache_lifetime setting will not work when $caching = 2.//提示:在$chching=2后面的$chche_lifetime不会起作用。// The cache lifetime for home.tpl has already been set// to 1 hour, and will no longer respect the value of $cache_lifetime.// home.tpl的缓存会话期设为1小时后,不会再按$cache_lifetime的值改变。// The home.tpl cache will still expire after 1 hour.// home.tpl的缓存会在1小时后结束。$smarty->cache_lifetime = 30; // 30 seconds$smarty->display('home.tpl');
Multiple Caches Per Page [每页多个缓存]
require('Smarty.class.php');$smarty = new Smarty;$smarty->caching = true;$my_cache_id = $_GET['article_id'];if(!$smarty->is_cached('index.tpl',$my_cache_id)) { // No cache available, do variable assignments here. $contents = get_database_contents(); $smarty->assign($contents);}$smarty->display('index.tpl',$my_cache_id);
Cache Groups [缓存集合]
require('Smarty.class.php');$smarty = new Smarty;$smarty->caching = true;// clear all caches with "sports|basketball" as the first two cache_id groups$smarty->clear_cache(null,"sports|basketball");// clear all caches with "sports" as the first cache_id group. This would// include "sports|basketball", or "sports|(anything)|(anything)|(anything)|..."$smarty->clear_cache(null,"sports");$smarty->display('index.tpl',"sports|basketball");
Controlling Cacheability of Plugins' Output [控制插件输出的缓冲能力]
index.php:
require('Smarty.class.php');$smarty = new Smarty;$smarty->caching = true;function remaining_seconds($params, &$smarty) { $remain = $params['endtime'] - time(); if ($remain >=0) return $remain . " second(s)"; else return "done";}$smarty->register_function('remaining', 'remaining_seconds', false, array('endtime'));if (!$smarty->is_cached('index.tpl')) { // fetch $obj from db and assign... $smarty->assign_by_ref('obj', $obj);}$smarty->display('index.tpl');
index.tpl:
Time Remaining: {remain endtime=$obj->endtime}
或:
index.php:
require('Smarty.class.php');$smarty = new Smarty;$smarty->caching = true;function smarty_block_dynamic($param, $content, &$smarty) { return $content;}$smarty->register_block('dynamic', 'smarty_block_dynamic', false);$smarty->display('index.tpl');
index.tpl:
Page created: {"0"|date_format:"%D %H:%M:%S"}
{dynamic}
Now is: {"0"|date_format:"%D %H:%M:%S"}
... do other stuff ...
{/dynamic}
- Smarty核心内容:Caching [缓存]
- Smarty核心内容:保留变量
- Smarty核心内容:变量调节器
- Smarty核心内容:内建函数
- Smarty核心内容:Smarty基本安装与调试
- Smarty核心内容:自定义函数及方法
- Caching Bitmaps 缓存Bitmap
- Caching Bitmaps [缓存位图]
- Caching Bitmaps 缓存位图
- Caching Bitmaps [缓存位图]
- Caching Bitmaps(缓存位图)
- Caching Bitmaps(缓存位图)
- 缓存Bitmap Caching Bitmaps
- spray-caching缓存结果
- php+smarty ,smarty 缓存
- smarty缓存
- smarty缓存
- smarty缓存
- Step by step Configuration FBA on SharePoint 2010 for Windows Server 2008 R2
- 求一个数组中的最大子段和
- 引用
- 你不知道的事---------printf输出指定长度字符串
- Smarty核心内容:自定义函数及方法
- Smarty核心内容:Caching [缓存]
- 不规则三角网(TIN)
- tcp udp 的echo脚本
- php标准注释
- VBA中MsgBox的几个用法
- Thoughts at one day
- Android最佳实践之:StrictMode介绍
- PHP 类与对象
- css中td截断多余的文字,不显示多余的和table-layout的fixed属性