Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/55.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 在codeigniter的单个缓存文件夹中管理两个不同的缓存文件_Php_Mysql_Codeigniter_Caching - Fatal编程技术网

Php 在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");

我需要一个帮助来解决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();
现在,当所有页面加载时,它会根据打开的页面创建一个缓存文件,如home、blog、blog+blogname等

这两个查询在缓存文件夹中生成两个缓存文件

1580e4c2413cb09f6ed3bc7fae8cee45
-第一个函数缓存结果
d7e2452b0424f859e1a5984bd26cbd6c
-第二个函数缓存结果

现在,我有两个问题:

  • 更新类别的货币表时,我需要删除1580e4c2413cb09f6ed3bc7fae8cee45缓存文件
  • 这个文件名是如何生成的?我指的是
    codeigniter
    如何生成缓存文件名。在我的缓存中,货币为1580e4c2413cb09f6ed3bc7fae8cee45,类别为d7e2452b0424f859e1a5984bd26cbd6c
  • 我希望这个解释是有意义的,我希望大多数
    codeigniter
    开发人员都有这个问题,需要解决

    谢谢,
    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;
    }