Php 在codeigniter的单个缓存文件夹中管理两个不同的缓存文件
我需要一个帮助来解决codeigniter缓存的一个问题 我正在运行两个函数将结果存储在缓存中。此功能在我的型号中:Php 在codeigniter的单个缓存文件夹中管理两个不同的缓存文件,php,mysql,codeigniter,caching,Php,Mysql,Codeigniter,Caching,我需要一个帮助来解决codeigniter缓存的一个问题 我正在运行两个函数将结果存储在缓存中。此功能在我的型号中: public function cacheAllCurrencies() { $this->db->cache_on(); $this->db->select("name,icon,currency_code"); $this->db->from("currency");
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();
现在,当所有页面加载时,它会根据打开的页面创建一个缓存文件,如home、blog、blog+blogname等
这两个查询在缓存文件夹中生成两个缓存文件
1580e4c2413cb09f6ed3bc7fae8cee45
-第一个函数缓存结果
d7e2452b0424f859e1a5984bd26cbd6c
-第二个函数缓存结果
现在,我有两个问题:
codeigniter
如何生成缓存文件名。在我的缓存中,货币为1580e4c2413cb09f6ed3bc7fae8cee45,类别为d7e2452b0424f859e1a5984bd26cbd6ccodeigniter
开发人员都有这个问题,需要解决
谢谢,
Ali在Codeigniter中,您可以使用表名清除DB的缓存 像 或同时使用两个表缓存
$this->db->cache_delete('currency','category');
编辑:
CodeIgniter通过SQL查询的md5()加密保存文件名
public function cacheAllCurrencies(){
$this->db->cache_on();
$this->db->select("name,icon,currency_code");
$this->db->from("currency");
$this->db->where("status='Active'");
//here you get filename
$file_name=md5($this->db->get_compiled_select());
$cache_currency_result = $this->db->get()->result();
$this->db->cache_off();
return $cache_currency_result;
}
2.看起来像MD5。@WillParky93:是的,看起来像MD5。但是什么名称被转换成md5呢?从第660行开始,缓存是从完整的uri创建的path@WillParky93:这两个查询运行的内容不同$file\u name=md5($this->db->get\u compiled\u select());答案是:)当我应用这段代码时,它会生成很多其他缓存文件,但当应用你的代码时,它会给我这个名字“c374e48f9b2cf50386c051b6dbec427b”,它不是
system/database/DB_cache中的correctcheck write()函数。php
可能是你的ci diff版本,使用diff逻辑来存储缓存文件。不,它现在正在工作。。但不能对另一个函数执行相同的操作。它给出了没有选择表的数据库错误。这两个表都工作正常。我需要在单行而不是多行中运行查询:$sql=$this->db->select('name,url')->from('category')->where('parent_category='0')->where('status='Active')->order_by('name','ASC')->get_compiled_select();;echomd5($sql);出口然后它会给我确切的名字:)
public function cacheAllCurrencies(){
$this->db->cache_on();
$this->db->select("name,icon,currency_code");
$this->db->from("currency");
$this->db->where("status='Active'");
//here you get filename
$file_name=md5($this->db->get_compiled_select());
$cache_currency_result = $this->db->get()->result();
$this->db->cache_off();
return $cache_currency_result;
}