在用建立一个站点(只用引擎也一样)时,开启缓存之后cache和templates_c这两个目录用不了多长时间就充满了上千个文件乃至几十万个文件,操作一个包含数量巨大的文件的目录本来就很慢,这样会导致这两个目录的文件读取、删除、更新都很慢,本打算写一个cache handler来解决这个问题,在跟踪代码的时候发现已经解决了这个问题,那就是use_sub_dirs属性,将该属性设置为true即可。示例代码

  1. <?php
  2.  
  3. require '../libs/Smarty.class.php';
  4.  
  5. $smarty = new Smarty;
  6.  
  7. $smarty->use_sub_dirs = true;
  8.  
  9. $smarty->compile_check = true;
  10. $smarty->debugging = true;
  11. $smarty->caching = true;
  12. $smarty->cache_lifetime = 60;
  13. $smarty->assign("Name","Fred Irving Johnathan Bradley Peppergill");
  14. $smarty->assign("FirstName",array("John","Mary","James","Henry"));
  15. $smarty->assign("LastName",array("Doe","Smith","Johnson","Case"));
  16. $smarty->assign("Class",array(array("A","B","C","D"), array("E", "F", "G", "H"),
  17.       array("I", "J", "K", "L"), array("M", "N", "O", "P")));
  18.  
  19. $smarty->assign("contacts", array(array("phone" => "1", "fax" => "2", "cell" => "3"),
  20.       array("phone" => "555-4444", "fax" => "555-3333", "cell" => "760-1234")));
  21.  
  22. $smarty->assign("option_values", array("NY","NE","KS","IA","OK","TX"));
  23. $smarty->assign("option_output", array("New York","Nebraska","Kansas","Iowa","Oklahoma","Texas"));
  24. $smarty->assign("option_selected", "NE");
  25.  
  26. $smarty->display('index.tpl');
  27.  
  28. ?>

对应中编辑Class\template.文件第58行附近更改var $use_sub_dirs = false;var $use_sub_dirs = true;即可。

标签:, , ,

, , ,

相关文章:

引用地址:http://web2world.cn/article/2007/04/a19.html

现在只有1个回复

  1. 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

Trackbacks & Pingbacks

  • 孤独之风-文章

    提高XOOPS的cache、templates_c目录读写性能…

    用Xoops建立一个站点(只用Smarty引擎也一样)时,开启缓存之后cache和templates_c这两个目录用不了多长时间就充满了上千个文件乃至几十万个文件,操作一个包含数量巨大的文件的目录本来就很…

要说点啥就在这吧

(若看不到验证码,请刷新网页。)