【发布时间】:2017-12-31 02:03:04
【问题描述】:
我需要帮助来找出与 codeigniter 缓存有关的一个问题。
我正在运行两个函数来将结果存储在缓存中。这个函数在我的模型中:
public function cacheAllCurrencies()
{
$this->db->cache_on();
$this->db->select("name,icon,currency_code");
$this->db->from("currency");
$this->db->where("status='Active'");
$cache_currency_result = $this->db->get()->result();
$this->db->cache_off();
return $cache_currency_result;
}
public function cacheAllCategory()
{
$this->db->cache_on();
$this->db->select("name,url");
$this->db->from("category");
$this->db->where("parent_category='0'");
$this->db->where("status='Active'");
$this->db->order_by('name','ASC');
$cache_category_result = $this->db->get()->result();
$this->db->cache_off();
return $cache_category_result;
}
My these two functions are called in header view like below :
$CI =& get_instance();
$CI->load->model(PUBLIC_DIR.'/commonPage','common');
$currencies = $CI->common->cacheAllCurrencies();
$categories = $CI->common->cacheAllCategory();
现在,当所有页面加载时,它会根据打开的页面(如主页、博客、博客+博客名称等)创建一个缓存文件。
两个查询都在缓存文件夹中生成两个缓存文件
1580e4c2413cb09f6ed3bc7fae8cee45 - 第一个函数缓存结果
d7e2452b0424f859e1a5984bd26cbd6c - 第二个函数缓存结果
现在,我有两个问题:
- 当我更新该类别的货币表时,我需要删除 1580e4c2413cb09f6ed3bc7fae8cee45 缓存文件。
- 这个文件名是怎么产生的?我的意思是
codeigniter如何生成缓存文件名。在我的缓存中1580e4c2413cb09f6ed3bc7fae8cee45用于货币,d7e2452b0424f859e1a5984bd26cbd6c用于类别。
我希望这个解释是有道理的,我希望大多数 codeigniter 开发人员遇到这个问题需要解决。
谢谢, 阿里
【问题讨论】:
-
2.看起来像 MD5。
-
@WillParky93 :是的,它似乎就像 md5。但是什么名字被转换成 md5 呢?
-
从codeigniter第660行,缓存是从完整的uri路径创建的
-
@WillParky93 : 这两个查询运行的不同
-
$file_name=md5($this->db->get_compiled_select());这就是答案:)
标签: php mysql codeigniter caching