//PHP 深度划分目录 smarty缓存配置实例【PHP进阶教程】 <?php /** * 为了存放缓存文件,不多,4w条记录,我想采用哈希目录; * 以两个字母为深度划分目录,想都没想我就这样写 * @link http://hi.baidu.com/anvycn/blog/item/3100242e751b34564fc2269f.html * @param $obj smarty object * @param $key URI * @param $_deep min(4,3) * @param $_time smarty cahce_lifetime */ function _set_cache(&$obj, $key = null, $_deep = 3, $_time = 30) { if ($key == null) { $key = $_SERVER['REQUEST_URI']; } $_path = md5($key); $_path_str = ''; for ($i = 0, $j = 0, $k = min(strlen($_path) / 2, $_deep); $i < $k; $i ++) { $_path_str .= $_path{$j ++} . $_path{$j ++} . '/'; } $obj->caching = true; $obj->cache_lifetime = $_time; echo $obj->cache_dir .= $_path_str; // require 'av_fso.php'; // Av_fso::mkdirs($obj->cache_dir); } require_once 'E:/smarty3/Smarty.class.php'; $smarty = new Smarty(); _set_cache($smarty);