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

[eluser]dmorin[/eluser]
You can use serialize() to serialize an object in which case it only stores the values of any class variables, not all of the function/methods/etc. My ORM-like models store an array of the current data record, so it would get cached. The issue that prompted me to start the thread is that CI loads the global CI instance into a var in each object so that you can do $this->db or use any other loaded reference. Because these are loaded, they also get serialized.

So my solution is to not extend the parent Model controller when creating these models. Instead, I'll use the trick used for libraries:

Code:
$this->CI = get_instance();

Then, before the object gets serialized, the __sleep() function is called automatically which I can use to unset $this->CI. When something is unserialized, such as when it is restored from memchached, it calls the __wakeup() method which I can use to restet the CI var.

Again, the advantage of this approach is that if I always use the models to represent the rows in the database, I never have to worry about invalidating old data. But there are other downsides, so I'm not sure its the best solution yet. Hope that makes sense.


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