views:

119

answers:

3

Is it advisable to store SQL Connection objects in memcache?

+3  A: 

I would not store a connection object in any type of cache. With connection pooling opening a connection is very quick, so there is no need to cache it.

JoshBerke
A: 

In PHP this isn't even possible. If you try and serialize a database connection handler or a file handler you're in for a surprise.

$f = fopen('handler-serialize.php', 'r');
var_dump(serialize($f));
fclose($f);

The output of this would be:

string 'i:0;' (length=4)

I don't know how this is handled in other languages, but I would presume that all languages do not allow you to store handlers to resources that might not exist anymore when the stored values are woken up at a later date.

So to answer you question, no it is not advisable to store Connection objects in memcached.

Miha Hribar
A: 

Do you realize you're asking if you can cache a connection behind a connection?

Caching: connect to memcached, fetch connection

No caching: connect to database

You can't get around a connection, so I really don't see why you would want to do this.

ryeguy