1

Trying to get to grips with the different types of cache engines File, APC, Xcache, Memcache. Anybody know of any good resources/links?

Note I am using Linux, PHP and mysql

skaffman
  • 398,947
  • 96
  • 818
  • 769
Lizard
  • 43,732
  • 39
  • 106
  • 167
  • 1
    This question might also help: http://stackoverflow.com/questions/2353008/selecting-an-appropriate-cache-mechanism – jasonbar Jan 13 '11 at 22:09

2 Answers2

2

There are 2 types of caching terminology thrown around in PHP.

First is an optcode cache: http://en.wikipedia.org/wiki/PHP_accelerator

Second is a data cache: http://simas.posterous.com/php-data-caching-techniques

A few of the technologies can cross boundaries into both realms, but the basics behind them are simple. The idea is: Keep as much data in ram and precompiled because compiling and HD seeks are very expensive processes. HD Seeks can be done to find a file to compile / query the DB to get data / looking for a temp file, and every time that happens it slows down the user experience.

Geoffrey Wagner
  • 818
  • 1
  • 5
  • 11
  • Other than local memory, hd seeks are probably the fastest available. – SlappyTheFish Jan 13 '11 at 22:14
  • Yes, but compared to using a caching engine that uses RAM, HD seeks are very very slow, and that is the point I am conveying. – Geoffrey Wagner Jan 13 '11 at 22:19
  • @SlappyTheFish haha what other options are there? Seek from some other servers HD? – dqhendricks Jan 13 '11 at 22:32
  • @dqhendricks I usually run across a few great articles a few times a month on google reader (from the normal sources like PHPDeveloper.org and PHP|Architect). Keeping up on sites like that has really driven home these concepts of how to effectively cache and why we should be caching. – Geoffrey Wagner Jan 13 '11 at 22:44
  • @SlappyTheFish You dont need a network for memcached. You can host that on the same machine as the web server so you are not using the network at all. Also you can make a memory table in a DB that (while still slower than Memcache because of the SQL layer on top it is still faster than reading from the HD) can reside on the same server as well. You can cut all networking out of the equation and look solely at RAM is always faster than HD. – Geoffrey Wagner Jan 13 '11 at 22:47
  • Local memory will always be fastest, all I'm saying is that HD seeks are not to be sniffed at when the alternative might be cross network, e.g. to a database or memcached, etc. – SlappyTheFish Jan 13 '11 at 22:47
  • @SlappyTheFish you are correct, Local RAM > Local HD > Network > WAN > Physical Files in some filing cabinet. – Geoffrey Wagner Jan 13 '11 at 22:48
  • @SlappyTheFish also i dont know why you keep bringing the network into this when network was not mentioned at all anywhere else but in YOUR OP – Geoffrey Wagner Jan 13 '11 at 22:50
  • @Slappy http://en.wikipedia.org/wiki/Memcached there are various sources around the internet about what is the best type of thing to do. APC is great but if your running both your OPTCODE and caching structure out of it, you can actually get a performance decrease, so splitting between different local services is a good thing as well. Be open to new ideas, i am not discounting your points at all. I understand where your coming from. Memcache isn't the only player in the market and others work just as well, – Geoffrey Wagner Jan 13 '11 at 22:54
0

Memcached is generally the way to go, but it has some "features" such as once you save some data to t cache, it doesn't necessarily guarantee that it will be available later as it dynamically removes old caches to make way for new ones. It's also fairly basic, you'll need to roll your own system for handling timeouts and preventing cascading but it's all fairly simple. There's tons of info in the Memcached FAQ, or feel free to ask and I'll post some code examples. Memcached can also act as a session handler which is great if you have lots of users or more than one server.

Otherwise disc caching is good if you only have one server or don't mind generating separate caches of each server. Generally faster than memcached as it doesn't have the network overhead (unless you have memcached on the same server). There are plenty of good disc caching frameworks but probably the best are Pear Cache_Lite and APC.

APC also has the added advantage that it can cache your compiled PHP code which may help on high-performance websites.

SlappyTheFish
  • 2,344
  • 3
  • 34
  • 41