0

I am looking for an in memory cache for my PHP powered website. It is not high traffic website, I just want to cache data and parts of some pages for improving performance. The data size will vary from a few bytes to few kBs. I am currently using xCache, and have no problem with it.

Is it better to switch to memcached or redis? Are there any better options?

Joyce Babu
  • 19,602
  • 13
  • 62
  • 97
  • Well, if you want an advantage of memcached: It can be distributed. For example you can't store sessions in APC if you have several PHP servers, because the session data will be stored only on one server, not on all of them ;) – NikiC Jan 29 '11 at 08:54

2 Answers2

1

If you don't have any obvious problem, why do wanna switch right now? Memcached or redis are probably better but if you don't need them right now, it is better to leave them. As long as your caching strategy is sound and cache interface is abstracted you should be able to add them later when you actually feel the need to switch to a scalable cache.

Also xCache in PHP is an opcoder cache.. Memcache & redis are more or less like a out of proc key Value pair.. If your site is running on 2 or 3 server and you need the context b.w them shared not just kept individual instances, those caches will help.

Sean Bright
  • 118,630
  • 17
  • 138
  • 146
Sai Venkat
  • 1,208
  • 9
  • 16
  • I was just asking for the advantages of switching to advanced solutions like memcache / redis. I couldn't find anything online, since it is not an apple to apple comparison. – Joyce Babu Jan 29 '11 at 08:23
  • 1
    Obviously not an apple comparison :). xCache is a inproc cache. Memcached or redis help you to cache frequently used serialized objects out of proc like page fragments or complex db queries. They remain out of proc so they can persist across server restarts. But when compared to xCache, they look slow but more scalable. – Sai Venkat Jan 29 '11 at 08:27
1

Personally, I use APC, because I already use it for Opcode Caching. This way I have to maintain fewer things. Another reason for me to use APC is, that it is planned to be included in the next PHP version, so I feel more "stable" on it.

Though obviously: You should change your caching system, just for the sake of changing it ;) If XCache doesn't make any problems, you probably should just keep it.

NikiC
  • 100,734
  • 37
  • 191
  • 225
  • I am using xcache for opcode caching too. By next PHP version did you mean PHP6? – Joyce Babu Jan 29 '11 at 08:20
  • 1
    @Joyce: No, PHP6 was cancelled. The next version is probably going to be PHP 5.4. – NikiC Jan 29 '11 at 08:36
  • Is PHP a LRU cache (like the OP wants)? I have never seen this explicitly stated in the docs, only discussion about TTL. – mpdonadio Jan 31 '11 at 00:48
  • @MPD: Well, APC hat TTL, so I would classify it as LRU. But I don't know much about that topic. – NikiC Jan 31 '11 at 08:38
  • @Joyce Oops, yeah I meant APC. @nikic LRU and TTL cache are not the same thing, and not necessarily mutually exclusive. For example, the docs for memcached state that the cache is LRU w/ expirations. – mpdonadio Jan 31 '11 at 11:50