CodeIgniter Forums
MP_Cache: Simple flexible Partial Caching - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: MP_Cache: Simple flexible Partial Caching (/showthread.php?tid=14852)

Pages: 1 2 3 4


MP_Cache: Simple flexible Partial Caching - El Forum - 08-12-2009

[eluser]Benedikt[/eluser]
Thanks Jelmer.

We made a comparison of Khoas and MP_CACHE. You seem not to use md5 for creating a key, right? This is what made Khaos a little slower than your class.

If you dont use md5 Khaos is slightly faster (0.008 seconds Smile).

Good work though. Have you thought about eAccelerator as Cache-Container?


MP_Cache: Simple flexible Partial Caching - El Forum - 08-12-2009

[eluser]Jelmer[/eluser]
My webhost doesn't support eAccelerator. And while I'd love to use it, I don't have access to it where it counts - which is why I haven't written anything for it.

About MD5: it's true I decided not to use it, but that was because I like my cache to be easily readable on the FTP and to be honest because I didn't see any reason to hash it.

About speed: I don't think there's unnecessary or ineffecient code in there, and anything that's not needed isn't called on (like date checking with dependencies or expiration). But if you have any suggestions on optimazation I'm always interested, the code is pretty straightforward I think.


MP_Cache: Simple flexible Partial Caching - El Forum - 08-12-2009

[eluser]Benedikt[/eluser]
Yes, I think md5-hashing is not necessary. Maybe if u hv user-dependent caching but in this case u need to protect ur cache-dir to external access anyway.

As Khaos and your implementation seem to have an almost identical syntax I guess it should be quite easy to add the eAccelerator and APC stuff. Maybe I can use the code from Khaos (the eAccelerator-Part) and add it to MP_CACHE. It would just extend the functionality.

Anyway, I like ur script and I guess I will use it.

If I have any suggestions, sure I will let you know.

Thanks for sharing,
Ben.


MP_Cache: Simple flexible Partial Caching - El Forum - 09-18-2009

[eluser]jof[/eluser]
Update: solved!

// johannes

Hi

Sorry for beeing stupied here, but I du get problems trying to cache the query result in to mp cache like this? What am I doing wrong?


$result = $this->mp_cache->get('text');

if ($result === false){
$result = $this->db->query('select * from table');
$this->mp_cache->write($result, 'text');
}

return $result->result();

// regards // johannes


MP_Cache: Simple flexible Partial Caching - El Forum - 09-23-2009

[eluser]Jelmer[/eluser]
For anyone else having such a problem: I'm guessing the problem was that you tried saving the CI database resource which didn't work. In which case the solution was saving the result instead of the resource, changing the code to:

Code:
$result = $this->mp_cache->get(‘text’);

if ($result === false){
  $result = $this->db->query(‘select * from table’);
  $result = $result->result();
  $this->mp_cache->write($result, ‘text’);
}

return $result;



MP_Cache: Simple flexible Partial Caching - El Forum - 12-04-2009

[eluser]swatkins[/eluser]
This is great code, and much appreciated. I've been needing to cache sections of the page for a while now and finally found your library which works like a charm.

I did have to update one line of code to get the recursive directories to work. On line 240, I had to change
Code:
if ( ! @mkdir($test_path)) return false;
to
Code:
if ( ! @mkdir($test_path, 0755, true)) return false;

That third argument is the recursive flag and without it, I could only get 1 level of folder written. After changing that, voila, a faster website!

Thanks so much, my visitors applaud you!


MP_Cache: Simple flexible Partial Caching - El Forum - 12-20-2009

[eluser]Jelmer[/eluser]
@swatkins

A bit of a late reaction, I didn't see it before. Thanks for the contribution! I'll add it to the library tomorrow for a 2.01 version.


MP_Cache: Simple flexible Partial Caching - El Forum - 01-28-2010

[eluser]Kaosland[/eluser]
Hello
I would like use your lib for put in cache some view, but i have not idea to do
So If somebody can show me how to do?
Tanks.


MP_Cache: Simple flexible Partial Caching - El Forum - 01-28-2010

[eluser]Jelmer[/eluser]
In order to use it in your view you first need access to the CodeIgniter superobject:
Code:
$ci =& get_instance();
If you haven't loaded it yet you can load it like this:
Code:
$ci->load->library('MP_Cache');
And after that you can use it like this:
Code:
$data = $ci->mp_cache->get('example');
if ($data === false)
{
    $data = 'data to cache';
    
    $ci->mp_cache->write($data, 'example');
}

I'd recommend doing the caching it the controller though, instead of in the view.


MP_Cache: Simple flexible Partial Caching - El Forum - 01-28-2010

[eluser]Kaosland[/eluser]
Thanks

i thinked use in controller, it's view I would put in cache.

I found how.
I show; if help futur readers
Code:
class Onecontroller extend controller{

function onename()
{

$datacache = $this->mp_cache->get('namecacheview');//read cache ?
if ($data === false)
{
    ...//execute code beacause don't cache exist
    .

    $datacahe = $string = $this->load->view('myfile', '', true);//get view
    
    $this->mp_cache->write($data, 'namecacheview',$expirationtime or not);// save the cache
}

$this->load->view('showcache',array('page'=>$datacache ));
}

}
/// VIEW SHOWCACHE.PHP
Code:
echo $page;

that all.