ZF-8856: Zend_Cache_Backend_Memcached bad performance on adding setting keys


In the Zend_Cache_Backend_Memcached->save method it tries memcache->add and if it fails does a memcache->set. The comment just above this code says that set() seems slower.

My tests indicate that add() and set() is almost identical in speed.

Also, if done in this way we assume that the cache-keys doesn't already exist most of the time (that add() doesn't fail). If add() fails, the saving of a cache will take double time.

I propose to just call memcache->set(), and not do add() at all. This will give consistent speed on saving the cache.


Yes, on replacing items all memcache requests are send twice. But in inserting new one the requests are send once but memcache isn't really faster because memcache have to check if the item exits anyway.

Therefor a simple set is enough.

I'm planing to integrate some new functionality (like add, replace, multiple interface etc.) but there few toto's: (…)

The add method was implemented by another issue:

save() performs a replace() when it's intending to do a set(), and replace() apparently doesn't work on older (<= 1.2.3) versions of memcached.

But I can't find any verifications for this testimony:

set() is rather slow in memcached

If replace doesn't work with memcached <= 1.2.3, I don't now why replace() is used within touch() ?!??! Can't find this replace() bug within memcached changelog. I will try to test out it within the next days.

I tested the replace command with memcached 1.2.3 but it works fine.

Fixed in r20590 (trunk) & r20591 (1.10 branch)