Horde_Memcache::replace PHP Method

replace() public method

Replace the value of a key.
See also: Memcache::replace()
public replace ( string $key, string $var, $expire ) : boolean
$key string The key.
$var string The data to store.
return boolean True on success, false if key doesn't exist.
    public function replace($key, $var, $expire = 0)
    {
        $var = @serialize($var);
        $len = strlen($var);
        if ($len > self::MAX_SIZE) {
            if (!empty($this->_params['large_items']) && $this->_memcache->get($this->_key($key))) {
                return $this->_set($key, $var, $expire, $len);
            }
            return false;
        }
        return $this->_memcache instanceof Memcached ? $this->_memcache->replace($key, $var, $expire) : $this->_memcache->replace($this->_key($key), $var, $this->_getFlags(1), $expire);
    }

Usage Example

Exemplo n.º 1
0
 /**
  */
 public function write($id, $session_data)
 {
     if (!empty($this->_params['track'])) {
         // Do a replace - the only time it should fail is if we are
         // writing a session for the first time.  If that is the case,
         // update the session tracker.
         $res = $this->_memcache->replace($id, $session_data);
         $track = !$res;
     } else {
         $res = $track = false;
     }
     if (!$res && !$this->_memcache->set($id, $session_data)) {
         return false;
     }
     if ($track) {
         $this->_memcache->lock($this->_trackID);
         $ids = $this->_memcache->get($this->_trackID);
         if ($ids === false) {
             $ids = array();
         }
         $ids[$id] = time();
         $this->_memcache->set($this->_trackID, $ids);
         $this->_memcache->unlock($this->_trackID);
     }
     return true;
 }
All Usage Examples Of Horde_Memcache::replace