Welcome Guest, Not a member yet? Register   Sign In
Cache library with memcache support
#1

[eluser]Lovecannon[/eluser]
Well, recently, I have been looking for ways to optimize my code and speed things up and to make sure things can scale properly. As a result of that search, I've found that opcode caching, distributed memory caching (such as memcached), and content caching seemed to be the most effective way of achieving that goal. Well, considering not everyone can get opcode caching and distributed memory, I took an existing fast content caching library (Al James caching library), and added support for memcache. The methods of retrieving and setting data to be cached, is the exact same (look at http://ellislab.com/forums/viewthread/57117/ for help), only difference is that there are methods to switch between memcache and file based caching. Also, the remove_group function does not do anything when memcache is being used.

Example use:
Code:
$this->load->library('cache');
//To use memcache
$this->cache->useMemcache($iptomemcache, $port); /*if you want, you can check to see if the connection even worked, as this will return false if the connection failed.*/
$this->cache->save('testkey', 'testdata', NULL, 3600); /*caches the testdata string for 1 hour. */
echo $this->cache->get('testkey');
//To switch back to file based caching
$this->cache->useFile();
//etc.

I havent gotten the chance to actually fully test the memcache feature, but it should work just fine. I would appreciate it if someone could test it out with memcached for me. Happy coding!

Download:
http://fuzzfist.com/upload/dl/jx01kuip
#2

[eluser]Lovecannon[/eluser]
Well, so far, with this library, Ive cut my script response time in half, from an initial 7-9ms, to 4-5ms. (Well, I stopped autoloading my database, and only loaded it on demand, but the cache itself cut the script down 2ms, and the loading on demand dropped it another 2ms)
#3

[eluser]jonnyjon[/eluser]
Is there a link to your new library?
#4

[eluser]Michael Wales[/eluser]
Elliot Haughin has published an absolutely fantastic article about benchmarking and caching.
#5

[eluser]Lovecannon[/eluser]
You gotta be kidding me...I forgot to post the link -_- I updated the article to have it.
#6

[eluser]obsesif[/eluser]
link not working?
#7

[eluser]esra[/eluser]
Attached is the file. About 2kb compressed.
#8

[eluser]Computerzworld[/eluser]
can i use this cache library in order to save my header? i am loading my header using
Code:
$this->load->view('header',$data)

So.. what i tried to do is
Code:
$this->cache->save('cachedHeader',$this->load->view("header", $data),NULL,3600);

But it didn't worked.. How can I exactly do this thing?
#9

[eluser]Wuushu[/eluser]
[quote author="Computerzworld" date="1235563027"]can i use this cache library in order to save my header? i am loading my header using
Code:
$this->load->view('header',$data)

So.. what i tried to do is
Code:
$this->cache->save('cachedHeader',$this->load->view("header", $data),NULL,3600);

But it didn't worked.. How can I exactly do this thing?[/quote]


Does it work if you instead do?:

$this->cache->save('cachedHeader',$this->load->view("header", $data, TRUE),NULL,3600);
#10

[eluser]Computerzworld[/eluser]
yes that workedSmile thanks...




Theme © iAndrew 2016 - Forum software by © MyBB