《CMS技巧:如何 提高v9的緩存加載速度?》要點:
本文介紹了CMS技巧:如何 提高v9的緩存加載速度?,希望對您有用。如果有疑問,可以聯系我們。
導讀:修改了 cache_file.class.php 的get方法,主要是防止同一頁面多次加載同一個緩存文件造成的效率低下.另外提醒一點,文件緩存如果采用serial...
修改了 cache_file.class.php 的get方法,主要是防止同一頁面多次加載同一個緩存文件造成的效率低下.另外提醒一點,文件緩存如果采用serialize方式,能提高1/3的讀取速度.‘?
代碼如下:
? ? ? ? public function get($name, $setting = '', $type = 'data', $module = ROUTE_M) {
??????????????? $this->get_setting($setting);
??????????????? if(empty($type)) $type = 'data';
??????????????? if(empty($module)) $module = ROUTE_M;
??????????????? $filepath = CACHE_PATH.'caches_'.$module.'/caches_'.$type.'/';
??????????????? $filename = $name.$this->_setting['suf'];
??????????????? //add 防止重復加載
??????? static $datas;
??????????????? $markid = md5($filepath.$filename);
??????????????? if($datas[$markid]) return $datas[$markid];
??????????????? //end
??????????????? if (!file_exists($filepath.$filename)) {
??????????????????????? return false;
??????????????? } else {
??????????????????? if($this->_setting['type'] == 'array') {
??????????????????????????? $data = @require($filepath.$filename);
??????????????????? } elseif($this->_setting['type'] == 'serialize') {
??????????????????????????? $data = unserialize(file_get_contents($filepath.$filename));
??????????????????? }
??????????????????? //add
??????????????????????? $datas[$markid] = $data;
??????????????????????? //end
??????????????????? return $data;
??????????????? }
??????? }
轉載請注明本頁網址:
http://www.snjht.com/jiaocheng/6053.html