ECSHOP's cache is stored in the templates/caches/article folder. Over time, this folder will become very large and slow down the website. There are many situations where we don't need his cache. This article describes how to disable ECSHOP caching.
ECSHOP's cache has two parts, one is SMARTY's page cache; the other is the cache of SQL query results. Both parts are saved in the templates/caches/ folder. As long as we turn off these two functions respectively, we can completely disable ECSHOP's cache. Of course, you can also turn off one of them according to your needs.
Recommended (free):ecshop
1. Turn off SMARTY’s cache
Openincludes/cls_template.php
, find the following paragraph
if (file_put_contents($this->cache_dir . ‘/’ . $cachename . ‘.php’, ‘’ . $data . $out) === false) { trigger_error(‘can’t write:’ . $this->cache_dir . ‘/’ . $cachename . ‘.php’); }
--Comment out this code
2. Turn off the SQL query result cache
Openincludes/cls_mysql.php
Find
var $max_cache_time=3600;//最大的缓存时间,以秒为单位
Change to
var $max_cache_time=0;//最大的缓存时间,以秒为单位
How to limit or disable ECShop cache? Logically speaking, you only need to log in to the host space server via ftp and clear the cache files in the "templates/caches" folder. However, a safer and more secure way is to enter the ecshop online store backend and click the "Clear Cache" button in the upper right corner. Or completely disable ecshop's caching function.
1. Disable caching of some data tables in ecshop
The cache files in the caches folder in ecshop include sql query result cache and SMARTY template page cache. If there are many users visiting the website, these temporary cached data will be kept in the "templates/caches" folder of ECshop. Data caching plays a certain role in improving the speed of online stores, but too many cached files are too much. Some people say that caching can be disabled only for the two tablesfavourable_activity, goods_activity
.
Open include/init.php, find
PHP code
$db->set_disable_cache_tables(array($ecs->table(’sessions’), $ecs->table(’sessions_data’), $ecs->table(’cart’)));
and modify it to
PHP code
$db->set_disable_cache_tables(array($ecs->table(’sessions’), $ecs->table(’sessions_data’), $ecs->table(’cart’), $ecs->table(’favourable_activity’), $ecs->table(’goods_activity’)));
two , completely disable the ecshop cache
You have to log in to the ecshop online store backend regularly to clear the cache files, which is quite troublesome for lazy people. Then simply disable ecshop caching completely. Refer to Xiao Chong's article on disabling echsop cache. Xiao Chong's specific code is around version 2.6.0. The method of disabling cache modification in 2.7 ecshop is similar:
1. Use editplus to open include/cls_template.php and comment out the following code:
PHP code
2. Use editplus Open include/cls_mysql.php, find max_cache_time = 300, and change 300 to 0
3. Can the files under templates/compiled be cleared?
templates The files under /compiled are template compiled files and can be cleared. It will be regenerated when the user browses the online store. The main problem in the templates folder is that there are too many cache files in the caches. You can clear the ecshop cache regularly or completely disable it.
----------------------------------------- --
Suggestions on clearing the cache!!
I found that the current clearing cache is relatively rough! There is no big change from before! It is the same as 2.0.5.
As long as there is any modification operation in the background, the entire cache will be gone! All used are $smarty->clear_all_cache();
Disadvantages: If I have 100,000 products and they have all been viewed, I A single operation in the background requires clearing more than 150,000 cached files:) It seems to be a bit extreme.
Just an example!! I hope ECSHOP will be more perfect!
Isn’t there this function in smarty?
clear_cache(), I made a small modification and added that you can specify to delete the cache in a certain directory. The purpose is: you can conveniently delete the category cache of the product!
I am on 2.0.5 This is changed, and a cache directorytemplates_caches
is created in the root directory, andarticle, article_cat, goods, goods_cat
are created in it. Four folders are used to store article content, article list, and product content. , Cache of product list
Example: Modification of products and articles
Add the following code to front-end init.php and back-end init.php. I added it directly to config.php for convenience.
//缓存目录设置 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';
The front-end product content and category cache time are separately set to be longer, such as one month for content and one day for category
Modify the backend, where the product is modified individually, only the cache of this product content is deleted
As long as there are modification operations, delete the product category cache and homepage cache! Add the following
$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:删除商品缓存,默认缓存时间
There are also advertising management, etc., etc., etc., etc., etc., etc., etc. need to be changed!
Front desk user Automatically delete this product cache after posting a comment, etc.......
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); } }
The above is the detailed content of Introducing ecshop clear mysql cache. For more information, please follow other related articles on the PHP Chinese website!