ZF2-135: CLONE - Memcache Semaphore Keys


While using the memcached backend there's no way to specify that a save should not occur if there is already a value in the cache thereby indirectly causing race conditions when adding a semaphore. By implementing an option to specify semaphoreIds this can be avoided.

        if (!(array_key_exists($id, $this->_options['semaphoreIds']))) {
            // ZF-8856: using set because add needs a second request if item already exists
            $result = @$this->_memcache->set($id, array($data, time(), $lifetime), $flag, $lifetime);
        } else {
            $result = $this->_memcache->add($id, array($data, time(), $lifetime), $flag, $lifetime);



Now there are the methods defined on interface: - setItem(s) - replace or add one or more items - addItem(s) - only add one or more items - replaceItem(s) - replace one or more existing items