I am using memcached on a web site, and I am currently needing to open connections to a database and socket each time a function is called. In the case of the db connection, I am having to decide at runtime, which database to connect to.
Because of the (default) stateless nature of web apps, I am having to tear down (i.e. close) the connection after each function call. I am wondering if it is possible to store (i.e. cache) the socket connection and the database connections in memcache – do that I have a pool of db connections and a socket connection already open that I can use whenever the function is called.
Is this safe ?
[[Additional Info]]
I will be interfacing to memcached primarily, with PHP and Python
BTW – memcached is running on the same machine (so physical address issues should not arise).
Both languages support database connections which live beyond the lifetime of a single request. Don’t use memcache for that!