在用Xoops建立一个站点(只用Smarty引擎也一样)时,开启缓存之后cache和templates_c这两个目录用不了多长时间就充满了上千个文件乃至几十万个文件,操作一个包含数量巨大的文件的目录本来就很慢,这样会导致这两个目录的文件读取、删除、更新都很慢,本打算写一个cache handler来解决这个问题,在跟踪Smarty代码的时候发现Smarty已经解决了这个问题,那就是Smarty的use_sub_dirs属性,将该属性设置为true即可。PHP示例代码
- <?php
- require '../libs/Smarty.class.php';
- $smarty = new Smarty;
- $smarty->use_sub_dirs = true;
- $smarty->compile_check = true;
- $smarty->debugging = true;
- $smarty->caching = true;
- $smarty->cache_lifetime = 60;
- $smarty->assign("Name","Fred Irving Johnathan Bradley Peppergill");
- $smarty->assign("FirstName",array("John","Mary","James","Henry"));
- $smarty->assign("LastName",array("Doe","Smith","Johnson","Case"));
- $smarty->assign("Class",array(array("A","B","C","D"), array("E", "F", "G", "H"),
- array("I", "J", "K", "L"), array("M", "N", "O", "P")));
- $smarty->assign("contacts", array(array("phone" => "1", "fax" => "2", "cell" => "3"),
- array("phone" => "555-4444", "fax" => "555-3333", "cell" => "760-1234")));
- $smarty->assign("option_values", array("NY","NE","KS","IA","OK","TX"));
- $smarty->assign("option_output", array("New York","Nebraska","Kansas","Iowa","Oklahoma","Texas"));
- $smarty->assign("option_selected", "NE");
- $smarty->display('index.tpl');
- ?>
对应Xoops中编辑Class\template.php文件第58行附近更改var $use_sub_dirs = false;为var $use_sub_dirs = true;即可。
标签:PHP, Smarty, XOOPS, 分级目录
webmaster@baidu.com
本文来源于Dominic.Xu’s 博客 http://web2world.cn , 原文地址: http://web2world.cn/article/2007/04/a19.html
023.cn Says @ 08-10-16 17:21