views:

80

answers:

2

Hey,

I'm working on some old(ish) software in PHP that maintains a $cache array to reduce the number of SQL queries. I was thinking of just putting memcached in its place and I'm wondering whether or not to get rid of the internal caching. Would there still be a worthwihle performance increase if I keep the internal caching, or would memcached suffice?

+2  A: 

It seems likely that memcache (which is implemented on the metal) would be faster than some php interpreted caching scheme.

However: if it's not broken, don't fix it.

If you remove the custom caching code, you might have to deal with other code that depends on the cache. I can't speak for the quality of the code you have to maintain but it seems like one of those "probably not worth it" things.

Let me put it this way: Do you trust the original developer(s) to have written code that will still work if you rip out the caching? (I probably wouldn't)

So unless the existing caching is giving you problems I would recommend against taking it out.

Kris
How do you figure that Memcache would be faster than an interpreted system (In general)? It involves TCP communication... Memcache is faster than querying the DB since both hit the network, but it's not necessarily faster than reading a php file from disk (`$foo = include('myfoofile.php');` where myfoofile.php contains `<?php return array('blah','blah','blah');`). Both require allocating memory, but only the php file can take advantage of a local opcode cache...
ircmaxell
Great advice... the situation is that the lead developer has left and left me (the new guy!) a mess of undocumented code. The caching isn't encapsulated at all, it's a global variable referenced thousands of times in the code that really affects readability and reeks of bad design, so from an architecture point of view (in my opinion!) it is broken :-)
waitinforatrain
@ircmaxell: I am assuming both hit the network because his question is about database access.
Kris
+1  A: 

There's an advantage in using memcache vs local caching if:

1) you have mulitple webservers running off the same database, and have memcache set up to run across multiple nodes

2) the database does not implement query result caching or is very slow to access

Otherwise, unless the caching code is very poor, you shouldn't expect to see much performance benefit.

HTH

C.

symcbean