Welcome Guest, Not a member yet? Register   Sign In
Codeigniter 2.1 + Datamapper 1.8.2 + Memcached
#1

[eluser]kpi[/eluser]
Hi all, I've been using Wanwizard's Datamapper for a while now and it's great!

I've also recently started reading up a bit on caching and I'm trying to figure out how to use Memcached with Datamapper but I'd like some advice to make sure I'm doing it right.

I know there's a driver for Memcached in CI. So, assuming I set up Memcached correctly, is this what happens when I want to make use of it:

Say I have a multi-user app where all the users share a DB table 'contacts'.

If I want to display Bob's contacts I'd first look for a 'contacts-425' key (assuming 425 is his id) in the cache, right?

Then, if that's not there I'd get the result from Datamapper (an object) and store it there for future use?

Is that good practice? Should I store the full DM object in there? Or is there a better way of doing it?

Is there a problem with creating cache keys on a user level?

Thanks
#2

[eluser]WanWizard[/eluser]
To avoid having to store the entire object, you can use the methods in the array extension to extract the data into an array, and to populate an empty object from an array.

You could create a method in your model called get_by_id($id), that would check if the record is in cache and populate the object from cache if so. And if not, call $this->where('id', $id)->get() to get it from the database, and store it in the case.
#3

[eluser]kpi[/eluser]
Thanks, I'll have a look at the array extension.




Theme © iAndrew 2016 - Forum software by © MyBB