ecshop缓存有关问题

fieldset{padding:10px;}

ecshop缓存问题

ECSHOP的缓存存放在templates/caches/文章夹下,时间长了这个文件夹就会非常庞大,拖慢网站速度。还有很多情况我们不需要他的缓存。本文介绍禁用ECSHOP缓存的方法。

  ECSHOP的缓存有两部分,一部分是SMARTY的页面缓存;另一部分是SQL查询结果的缓存。这两部分都是保存在templates/caches/文件夹下。只要我们分别关闭这两个功能,就可以完全禁用ECSHOP的缓存。当然你也可以根据自己的需要关闭其中某一个。

  1.关闭SMARTY的缓存:  打开includes/cls_template.php,找到下面一段

  if (file_put_contents($this->cache_dir . ‘/’ . $cachename . ‘.php’, ‘<?php exit;?>’ . $data . $out) === false) { trigger_error(’can\’t write:’ . $this->cache_dir . ‘/’ . $cachename . ‘.php’); }

  将这一部分注释掉即可,改成

/*  if (file_put_contents($this->cache_dir . ‘/’ . $cachename . ‘.php’, ‘<?php exit;?>’ . $data . $out) === false) { trigger_error(’can\’t write:’ . $this->cache_dir . ‘/’ . $cachename . ‘.php’); }*/

  2.关闭SQL查询结果缓存  打开includes/cls_mysql.php   找到  var $max_cache_time=3600;//最大的缓存时间,以秒为单位  改为   var $max_cache_time=0;//最大的缓存时间,以秒为单位

--------------------------------------------

如何限制或禁用ECShop缓存呢?按道理只要ftp登录到主机空间服务器,清除“templates/caches”文件夹下的缓存文件,但比较安全稳妥的办法是进入ecshop网店后台点击右上角“清除缓存”按钮。还是完全禁用ecshop的缓存功能。

一、禁用ecshop部分数据表缓存。ecshop里caches文件夹缓存文件包括sql查询结果缓存和SMARTY模板页面缓存。如果访问网站的用户一多,这些临时的缓存数据都被保持在ECshop的“templates/caches”文件夹下。数据缓存对提高网店速度有一定作用,但缓存文件一多也就过犹不及。有人说只对favourable_activity,goods_activity这2个表禁用缓存即可。打开include/init.php,找到

PHP代码

    $db->set_disable_cache_tables(array($ecs->table(’sessions’), $ecs->table(’sessions_data’), $ecs->table(’cart’)));

修改为

PHP代码

    $db->set_disable_cache_tables(array($ecs->table(’sessions’), $ecs->table(’sessions_data’), $ecs->table(’cart’), $ecs->table(’favourable_activity’), $ecs->table(’goods_activity’)));

二、完全禁用ecshop缓存定期要登录ecshop网店后台清除缓存文件,对于懒人来说,这也挺嫌麻烦的。那干脆完全禁用ecshop缓存吧。参考小虫的禁用echsop缓存文章,小虫的具体代码是2.6.0左右的版本。2.7的ecshop禁用缓存修改方法类似:

1. 用editplus打开include/cls_template.php,把下面代码注释掉:

PHP代码

    /* if (file_put_contents($hash_dir . ‘/’ . $cachename . ‘.php’, ‘<?php exit;?>’ . $data . $out, LOCK_EX) === false) { trigger_error(’can\’t write:’ . $hash_dir . ‘/’ . $cachename . ‘.php’); } */

2.用editplus打开include/cls_mysql.php,找到 max_cache_time = 300,把300改为0即可

三、templates/compiled下的文件是否可以清空?templates/compiled下的文件是模板编译后文件,可以清空。当用户浏览网店后又会重新生成。templates文件夹下的主要是caches里缓存文件太多,你可以定期清空或完全禁用ecshop缓存。

----------------------------------------------

关于清除缓存的建议!! 发现现在的清除缓存做的比较粗!和之前没大变化啊!和2.0.5一样.只要后台随便一个修改的操作,整个缓存就都没了!用的都是$smarty->clear_all_cache();缺点:如果我有10万商品,:),而且都被浏览过,我后台一个操作就要清楚15万多缓存文件:)似乎极限了点只是举例!!,希望ECSHOP更加完美而已!smarty里面不是有这个函数么?clear_cache(),我小修改了下,增加了可以指定删除某个目录下的缓存,用处是:可方便的删除商品的分类缓存!2.0.5上我是这么改的,另外在根目录建立一个缓存目录templates_caches,里面建立article,article_cat,goods,goods_cat,4个文件夹分别放文章内容,文章列表,商品内容,商品列表的缓存例子:对商品,文章部分的修改前台init.php和后台init.php加入如下代码,我为了方便直接加在config.php里面了

    //缓存目录设置define(‘ECS_ROOT’, substr(dirname(__FILE__), 0, -8));//前后台数字当然不一样了:)//文章缓存$cache_dir_article = ECS_ROOT.’./templates_caches/article’;$cache_dir_article_cat = ECS_ROOT.’./templates_caches/article_cat’;//商品缓存$cache_dir_goods = ECS_ROOT.’./templates_caches/goods’;$cache_dir_goods_cat = ECS_ROOT.’./templates_caches/goods_cat’;

复制代码 前台商品内容和分类缓存时间单独设置长一些,如内容一个月,分类1天修改后台,商品单独修改的地方只删除这个商品内容的缓存只要有修改操作就删除商品分类缓存和首页缓存!加入如下$smarty->clear_cache(null, null, null, null, $cache_dir_goods_cat);//zouql:删除商品目录缓存,默认缓存时间$smarty->clear_cache(‘goods.html’, $goods_id, null, null, $cache_dir_goods);//zouql:删除商品缓存,默认缓存时间还有广告管理等等等等等等等等地方要改!前台用户发表评论后自动删除本商品缓存等等……….function clear_cache($tpl_file = null, $cache_id = null, $compile_id = null, $exp_time = null, $cache_dir = null){ if (!isset($cache_dir)) $cache_dir = $this->cache_dir;if (!isset($compile_id)) $compile_id = $this->compile_id; if (!isset($tpl_file)) $compile_id = null; $_auto_id = $this->_get_auto_id($cache_id, $compile_id); if (!empty($this->cache_handler_func)) { return call_user_func_array($this->cache_handler_func, array(‘clear’, &$this, &$dummy, $tpl_file, $cache_id, $compile_id, $exp_time)); } else { $_params = array(‘auto_base’ => $cache_dir, ‘auto_source’ => $tpl_file, ‘auto_id’ => $_auto_id, ‘exp_time’ => $exp_time); require_once(SMARTY_CORE_DIR . ‘core.rm_auto.php’); return smarty_core_rm_auto($_params, $this); }}家!甜蜜的家!天下最美好的莫过於家

ecshop缓存有关问题

相关文章:

你感兴趣的文章:

标签云: