Forums / General / which lib to use with memcache

which lib to use with memcache

Author Message

Stéphane Couzinier

Thursday 23 April 2009 9:13:13 am

Hi

There are 2 lib to deal with memcache server:
http://fr.php.net/memcache/
http://fr.php.net/memcached

memcached look better but it's a beta version.

Somebody have test it?

http://www.kouz-cooking.fr

André R.

Thursday 23 April 2009 2:31:35 pm

No, but what about witing a small class with functions that wrap around these functions and do code you'll need for you as well. Makes it easier to switch back and forth, you can also change it to write to db if you want to... :P

eZ Online Editor 5: http://projects.ez.no/ezoe || eZJSCore (Ajax): http://projects.ez.no/ezjscore || eZ Publish EE http://ez.no/eZPublish/eZ-Publish-Enterprise-Subscription
@: http://twitter.com/andrerom

Stéphane Couzinier

Thursday 23 April 2009 2:58:01 pm

Salut andré

We will do something like this but it's a bit difficult to test correctly memcache.(simulate a lof of traffic. the server never work a lot;-) )
The beta version memcached have better function than the stable one but it's a beta version...

http://www.kouz-cooking.fr

André R.

Friday 24 April 2009 12:42:34 am

I would maybe aim at the beta, so the abstractions include the functions you have there witch can be very valuable ( :append, ::setMulti and ::setMultiByKey among others...).

So the abstraction would be like

public function append( $key, $value )
{
    if ( $this->mem !== null )
    {
        $this->mem->append( $key, $value );
        return true;
    }
    return false;
}

So if you need to downgrade because of instability you would hav to do something like:

public function append( $key, $value )
{
    if ( $this->mem !== null )
    {
        $currentValue = $this->mem->get( $key );
        if ( $currentValue === false )
            $this->mem->set( $key, $value );
        else
            $this->mem->set( $key, $currentValue . $value );
        return true;
    }
    return false;
}

I suggest a object approach to the abstraction class, perferably with a singleton pattern ( stMemCache::getInstance() -> self::$instance === null -> protected function __construct() -> return self::$instance; ).
But it can just as well be done on a all static class, where you call stMemCache::init() first to set self::$mem (instead of $this->mem).

Sorry that I can't really answear your first question on what to choose, any one here who have tried Memcached?

eZ Online Editor 5: http://projects.ez.no/ezoe || eZJSCore (Ajax): http://projects.ez.no/ezjscore || eZ Publish EE http://ez.no/eZPublish/eZ-Publish-Enterprise-Subscription
@: http://twitter.com/andrerom