tags:

views:

97

answers:

1

Take this code for example

$memcache= new Memcache();
$memcache->connect('127.0.0.1', 11211);

$rows2= $memcache->get('therows1');
if($rows2 == ''){
    $myfriends = findfriend2();
    $memcache->set('therows1', $myfriends, 0, 30);
}else{
    echo '<pre>';
    print_r($rows2);
    echo '</pre>';
}

The connection; $memcache->connect('127.0.0.1', 11211);

Does this need to be called several times on a page or just 1 time per page load?

And then this way

$memcache_obj = memcache_connect('memcache_host', 11211);
$var = memcache_get($memcache_obj, 'some_key');

It appears $memcache_obj is called on every action you do on that page, does that mean it would be bad performance to for instance call 5 seperate memcached items on a page?

A: 

You call it once per page load. The phrasing of your second question confuses me. Once you connect to memcache, it's no different really than connecting to a MySQL database. You establish the connection, and then query it. There is no "performance hit" for querying memcache besides the additional call.

I suggest you read the documentation and check the examples.

hobodave