Welcome Guest, Not a member yet? Register   Sign In
MP_Cache: Simple flexible Partial Caching
#11

[eluser]Phil Sturgeon[/eluser]
Forgot to thank you again. This has sped PyroCMS quite a bit.
#12

[eluser]Jelmer[/eluser]
Hey Phil,

Thanks for the complements, at this point I'm very happy to hear the experiences with it from others. That helps me a lot to improve the library.

Have you looked at the second version I mentioned above? I've solved the problem there by putting any input into an array as a property and add information like the time of creation and expiration time at that level. This solves the problem of contamination and only adds a small amount of overhead to the serialized files.

The second version isn't fully untested though, its basic functionality is being used by the site its on. It's just that I haven't had the time to implement (and thus fully test) the dependencies concept.
#13

[eluser]Erdal Demirtas[/eluser]
Hi,

thank you for sharing.

Did you see KhCache ?

It seems that they do nearly the same thing.

Are there any differences, or advantages for using MP_Cache?
#14

[eluser]Jelmer[/eluser]
I hadn't seen it before, seems like it does indeed do pretty much the same. Pretty funny if you look at the release dates, I was pretty amazed no one had created such a library before me and he created his in the same week as I first published mine.
[EDIT: I was wrong, forgot to look at the year and apparently missed his while creating MP_Cache]

On the differences. I haven't looked in depth at his library, but one of the advantages of his is that he supports APC - something I'm not planning on as my host doesn't support it. There are also some implementation differences, I didn't get why he seems to fetch the cache twice. (he starts out the same way mine does, but than seems to fetch it a second time with the call() function)

I kinda like the automatic cache cleaning he does, maybe I'll implement something similar but it isn't really my priority at this point.

The differences are at the core mostly in the implementation. KhCache has the advantage of supporting APC for those who have a server that supports it. Other than that its not much difference. One difference is that he hashes the cache filenames, while I decided to name them and allow for subdirectories. The latter allows for grouping several caches and deleting them while keeping others.
Also the 'dependencies' feature (which is included in the new version) is an advantage of MP_Cache.
#15

[eluser]Erdal Demirtas[/eluser]
Thanks for the comparison!

[quote author="Jelmer" date="1240283800"] he created his in the same week as I first published mine.
[/quote]

Did you look at the years?

KhCache was released a year ago -> 2008 Smile
#16

[eluser]Jelmer[/eluser]
Oops, you're completely right. I apprently overlooked his completely when searching for a caching solution...

Also edited the comparisson post a bit about filenames and dependencies in the last paragraph.
#17

[eluser]Phil Sturgeon[/eluser]
Added a new function to my verion of this library.

Code:
function call($property, $method, $arguments = array(), $expires = null)
    {
        // Clean given arguments to a 0-index array
        $arguments = array_values($arguments);
        
        $cache_file = $property.'/' . $method . '-'.md5(serialize($arguments));
        
        // See if we have this cached
        $cached_responce = $this->get($cache_file);

        // Not FALSE? Return it
        if($cached_responce)
        {
            return $cached_responce;
        }
        
        else
        {
            // Call the model or library with the method provided and the same arguments
            $new_responce = call_user_func_array(array($this->ci->$property, $method), $arguments);
            $this->write($new_responce, $cache_file, $expires);
            
            return $new_responce;
        }
    }

I spent ages trying to think of a brilliant OOP overloaded way of caching model/library without modifiying it. Tried extending the Models class and all sorts of crazyness, but in the end I ended up with this syntax.

Code:
$this->data->page = $this->cache->call('pages_m', 'getBySlug', array($slug, DEFAULT_LANGUAGE), $this->settings->item('page_cache'))

The parameters are model name, method name and then an array of params for that method. Also added a 4th param for cache expirey to act in the same way as your other functions.

Use it if you like, up to you. :-)
#18

[eluser]Jelmer[/eluser]
I did some important bugfixes:
- PHP notices & warnings should be gone with error_reporting(E_ALL)
- The non-object usage of the write() function now doesn't expire directly anymore when the expiration isn't set (but doesn't expire at all, as it used to be)
- The default_expiration config setting functions as it should

I feel kinda comfortable removing the beta indication from the version number, so I've called this one 2.0 (final). I'm testing the application I wrote it for even more today and tommorrow so there might be a 2.01 very soon if I run into any more bugs.

Download it here
#19

[eluser]Benedikt[/eluser]
I like this library. Thanks a lot Jelmer.

I am thinking to extend your library by adding support for eAccelerator as this is what I use mainly as OPCode-Cache.

I cant tell there would be any performance increase but maybe we are lucky. eAccelerator should be supported by almost every webhosting-company in the world Smile

If I have sth to show u I will post it here.

Thanks for your work Jelmer!!

One question: Can I store objects in the cache and retrieve them with its previous status? You wrote that objects would lose "references". What is meant by that? Can you give me an example?
#20

[eluser]Jelmer[/eluser]
Quote:One question: Can I store objects in the cache and retrieve them with its previous status? You wrote that objects would lose “references”. What is meant by that? Can you give me an example?

Objects & arrays are saved serialized and the serialization saves the type of object and the values of its properties. But if I remember correctly properties that contian a reference to another object can't be saved.

There's more on what can't and can be saved on http://www.php.net/manual/en/function.serialize.php since that's the function that is responsible for making it possible to save arrays & objects as files.




Theme © iAndrew 2016 - Forum software by © MyBB