在codeigniter的单个缓存文件夹中管理两个不同的缓存文件 [英] Manage Two Different Cache file in single cache folder in codeigniter

查看:138
本文介绍了在codeigniter的单个缓存文件夹中管理两个不同的缓存文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要帮助来找出Codeigniter缓存的一个问题.

I need a help to figure out one issue with the codeigniter caching.

我正在运行两个函数以将结果存储在缓存中.此功能在我的模型中:

I am running two functions to store a result in cache. This function is in my model :

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();

现在,当所有页面加载完毕后,它会根据打开的页面(例如首页,博客,博客+博客名称等)创建一个缓存文件.

Now, when all the page loads, it creates a cache file according to the page opened like home, blog, blog+blogname etc.

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

Both query generates two cache file in cache folder

1580e4c2413cb09f6ed3bc7fae8cee45-第一个功能缓存结果 d7e2452b0424f859e1a5984bd26cbd6c-第二个功能缓存结果

1580e4c2413cb09f6ed3bc7fae8cee45 - first function cache result d7e2452b0424f859e1a5984bd26cbd6c - second function cache result

现在,我有两个问题:

  1. 更新类别的货币表相同时,我需要删除1580e4c2413cb09f6ed3bc7fae8cee45缓存文件.
  2. 此文件名是如何生成的?我的意思是codeigniter如何生成缓存文件名.在我的缓存中,1580e4c2413cb09f6ed3bc7fae8cee45表示货币,d7e2452b0424f859e1a5984bd26cbd6c表示类别.
  1. I need to delete 1580e4c2413cb09f6ed3bc7fae8cee45 cache file when I update currency table same for the category.
  2. How this file name generated ? I mean how codeigniter generates cache file name. In my cache 1580e4c2413cb09f6ed3bc7fae8cee45 for currency and d7e2452b0424f859e1a5984bd26cbd6c for category.

我希望这种解释是有意义的,并且希望大多数codeigniter开发人员遇到此问题,需要对其进行解决.

I hope this explanation makes sense and I hope most of the codeigniter developer having this problem which need to be sort it out.

谢谢, 阿里

推荐答案

Codeigniter 中,您可以使用表名清除数据库的缓存 喜欢

In Codeigniter, you can clear the cache of DB using the table name like

$this->db->cache_delete('currency');
$this->db->cache_delete('category');

或同时缓存两个表

$this->db->cache_delete('currency','category');

CodeIgniter通过md5()SQL查询加密来保存文件名

EDIT : CodeIgniter save filename by md5() encryption of SQL query

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

这篇关于在codeigniter的单个缓存文件夹中管理两个不同的缓存文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆