Welcome Guest, Not a member yet? Register   Sign In
Caching Models with Memcached?
#14

[eluser]freakylp[/eluser]
Im not so quite sure about caching models.
First of all you dont have the same queries except if you have only static queries ( with static I mean queries without any dynamic parameters ).

Caching models is not solution.If you cache the model you will not have fresh data too.
Lets say that we have News_model which has 3 methods.
News_model.php
Code:
public function Get_News_By_Id( $news_id )
    {
        $news_id = (int)$news_id;
        $query = $this->db->query("SELECT * FROM news WHERE id = '$news_id'");
        return $query->result();
    }
    
    
    
    public function Get_News_Title( $news_id )
    {
        $news_id = (int)$news_id;
        $query = $this->db->query("SELECT title FROM news WHERE id = '$news_id'");
        return $query->result();
    }

Lets say that we have a News_Controller:
News_Controller
Code:
class News_Controller extends Controller{

    public function __construct()
    {
        parent::__construct();
        $this->load->model('News_Model','news');    
    }
    
    
    public function Index()
    {
        $this->data['news']     = $this->news->Get_News_By_Id(5);
        $this->data['title']    = $this->news_Get_News_Title(5);    
    }
    
}

If we cache $this->news and parameter of methods of News_Model are not the same we will have 1 copy of News_model object resource but we dont have the same data.

What we shall do ?


Messages In This Thread
Caching Models with Memcached? - by El Forum - 12-15-2008, 10:42 AM
Caching Models with Memcached? - by El Forum - 12-15-2008, 11:33 AM
Caching Models with Memcached? - by El Forum - 12-15-2008, 11:40 AM
Caching Models with Memcached? - by El Forum - 12-15-2008, 03:09 PM
Caching Models with Memcached? - by El Forum - 12-15-2008, 03:18 PM
Caching Models with Memcached? - by El Forum - 12-20-2008, 10:35 PM
Caching Models with Memcached? - by El Forum - 12-21-2008, 04:15 PM
Caching Models with Memcached? - by El Forum - 01-13-2009, 09:18 PM
Caching Models with Memcached? - by El Forum - 01-13-2009, 09:24 PM
Caching Models with Memcached? - by El Forum - 01-13-2009, 09:59 PM
Caching Models with Memcached? - by El Forum - 01-14-2009, 08:38 AM
Caching Models with Memcached? - by El Forum - 01-14-2009, 08:54 AM
Caching Models with Memcached? - by El Forum - 01-14-2009, 09:13 AM
Caching Models with Memcached? - by El Forum - 01-14-2009, 09:45 PM
Caching Models with Memcached? - by El Forum - 01-15-2009, 08:51 AM
Caching Models with Memcached? - by El Forum - 01-16-2009, 05:53 AM
Caching Models with Memcached? - by El Forum - 01-16-2009, 08:44 AM
Caching Models with Memcached? - by El Forum - 01-24-2009, 10:51 PM



Theme © iAndrew 2016 - Forum software by © MyBB