Part of the EllisLab Network
   
 
Memcache DB_cache Replacement
Posted: 08 August 2009 06:10 PM   [ Ignore ]  
Summer Student
Avatar
Total Posts:  11
Joined  07-04-2009

Hey guys,

I have been working with CI now for a couple of months for my startup and we thought we’d start putting out some of our code for community review. So far the community has been great, and we’ve really not had anything substantial to contribute until now. So here’s a little something something we’ve been using. Let us know if you guys see any improvements, and feel free to leave suggestions.

We are planning on putting up a git repository on our website at http://code.zinkkinc.com/ but I have not had the chance to do so yet. If all goes well I’ll have that going by Monday morning, and we’ll have a proper place to display our contributions.

Memcache Replacement for Standard DB Disk cache

As I said above we work with heavy database applications and we are always looking for ways to speed up our web applications’ queries. So I took a couple of hours and rewrote the release version of DB_cache.php to use memcache where available, and if not fall back to disk caching. I’m attaching the file to the post, and the only thing that you have to is add the following entry to your database configuration:

$db[‘default’][‘mc_hosts’][] = array (“ip”=>‘127.0.0.1’, “port”=>11211);

If you find any bugs, have any questions, or find a better way to do something feel free to reply to the thread, or shoot me an e-mail jb at zinkkinc.com. Thanks all, we’ve had some awesome fun with CI and hope to be able to contribute to everyone.

File Attachments
DB_cache.php.tgz  (File Size: 2KB - Downloads: 206)
Profile
 
 
Posted: 09 August 2009 02:11 PM   [ Ignore ]   [ # 1 ]  
Lab Assistant
Avatar
RankRank
Total Posts:  119
Joined  03-24-2007

Nice one, I’m gonna try it as soon as possible.

Thanks for sharing !

 Signature 

Twitter | Facturation en ligne avec iScriba (one of my CodeIgniter apps)

Profile
 
 
Posted: 10 August 2009 12:50 PM   [ Ignore ]   [ # 2 ]  
Summer Student
Avatar
Total Posts:  11
Joined  07-04-2009

Caught a bug myself after wondering why some of the entries in our system were from Thursday. The quick fix is to replace Line 106 with the following tidbit of code:

return memcache_set ($this->MC, md5 ($segment_one . $segment_two . $sql), $object, 0, $expires);

The fourth parameter in the function is for compression, and the last is for expires. So if expires is zero items inside of the cache last indefinitely (which basically amounts to until they get written over).

File Attachments
DB_cache.php.tgz  (File Size: 2KB - Downloads: 172)
Profile