Adds entry into memcache/apc DB.

@param string $key  Cache key name
@param mixed  $data Serialized cache data

@param boolean True on success, False on failure
546977
private function add_record($key, $data)
    {
        if ($this->type == 'memcache') {
            $result = $this->db->replace($key, $data, MEMCACHE_COMPRESSED, $this->ttl);

            if (!$result) {
                $result = $this->db->set($key, $data, MEMCACHE_COMPRESSED, $this->ttl);
            }
        }
        else if ($this->type == 'apc') {
            if (apc_exists($key)) {
                apc_delete($key);
            }

            $result = apc_store($key, $data, $this->ttl);
        }

        if ($this->debug) {
            $this->debug('set', $key, $data, $result);
        }

        return $result;
    }
972765
protected function checkKeyExists($data, $key)
    {
        if (!$data->has($key)) {
            $this->output->writeln("<error>The key $key does not exist.");

            return false;
        }

        return true;
    }
934477
public function set($key, $data) {
        if (!is_array($key)) {
            $record = array(
                'key' => $key
            );
        } else {
            $record = $key;
        }
        $record['data'] = serialize($data);
        $options = array('upsert' => true);

        $w = $this->usesafe ? 1 : 0;
        $wc = new MongoDB\Driver\WriteConcern($w);

        $options['writeConcern'] = $wc;

        $this->delete($key);
        try {
            $this->collection->insertOne($record, $options);
        } catch (MongoDB\Exception\Exception $e) {
            return false;
        }

        return true;
    }
462932
private function write_record($key, $data)
    {
        if (!$this->db) {
            return false;
        }

        // don't attempt to write too big data sets
        if (strlen($data) > $this->max_packet_size()) {
            trigger_error("rcube_cache: max_packet_size ($this->max_packet) exceeded for key $key. Tried to write " . strlen($data) . " bytes", E_USER_WARNING);
            return false;
        }

        if ($this->type == 'memcache' || $this->type == 'apc') {
            $result = $this->add_record($this->ckey($key), $data);

            // make sure index will be updated
            if ($result) {
                if (!array_key_exists($key, $this->cache_sums)) {
                    $this->cache_sums[$key] = true;
                }

                $this->load_index();

                if (!$this->index_changed && !in_array($key, $this->index)) {
                    $this->index_changed = true;
                }
            }

            return $result;
        }

        $db_key = $this->prefix . '.' . $key;

        // Remove NULL rows (here we don't need to check if the record exist)
        if ($data == 'N;') {
            $result = $this->db->query(
                "DELETE FROM {$this->table}".
                " WHERE `user_id` = ? AND `cache_key` = ?",
                $this->userid, $db_key);

            return !$this->db->is_error($result);
        }

        $key_exists = array_key_exists($key, $this->cache_sums);
        $expires    = $this->ttl ? $this->db->now($this->ttl) : 'NULL';

        if (!$key_exists) {
            // Try INSERT temporarily ignoring "duplicate key" errors
            $this->db->set_option('ignore_key_errors', true);

            $result = $this->db->query(
                "INSERT INTO {$this->table} (`expires`, `user_id`, `cache_key`, `data`)"
                . " VALUES ($expires, ?, ?, ?)",
                $this->userid, $db_key, $data);

            $this->db->set_option('ignore_key_errors', false);
        }

        // otherwise try UPDATE
        if (!isset($result) || !($count = $this->db->affected_rows($result))) {
            $result = $this->db->query(
                "UPDATE {$this->table} SET `expires` = $expires, `data` = ?"
                . " WHERE `user_id` = ? AND `cache_key` = ?",
                $data, $this->userid, $db_key);

            $count = $this->db->affected_rows($result);
        }

        return $count > 0;
    }
329279
public function addParameter($key, $data)
    {
        if (!is_string($key)) {
            throw new \RuntimeException('Only strings can be given as parameter keys. Got "' . gettype($key) . '".');
        }

        if (!is_string($data) && !is_callable($data)) {
            throw new \RuntimeException('The "data" parameter must either be a string or a callable. . Got "' . gettype($key) . '".');
        }

        if (isset($this->parameters[$key])) {
            throw new \RuntimeException('The parameter key "' . $key . '" is already set.');
        }

        $this->parameters[$key] = $data;

        return $this;
    }
984404
public function add($id, $data = 1)
    {
        try {
            return $this->resource->hSet(static::CACHE_KEY, $id, $data);
        } catch (ConnectionException $e) {
            return false;
        }
    }
1292715
@Override
    public void add(final byte[] key, final byte[] data) throws IOException {
        this.datas.put(new BytesKey(key), data);
    }
642053
public function save(array $data, $key)
    {
        $this->redis->set($this->decorateKey($key), $data);
    }
841583
private static function recursiveKeyExist($data, $key)
    {
        if (empty($key)) {
            return true;
        } else {
            $currentKey = array_shift($key);
            return isset($data[$currentKey]) ? self::recursiveKeyExist($data[$currentKey], $key) : false;
        }
    }
36710
public function setData($data, $key = null)
	{
		if (is_array($data) && $key === null) {
			$this->data = $data;

			return $this;
		}

		if ($key === null)
			$key = 'data';

		$this->data[$key] = $data;

		return $this;
	}
722257
protected function parseSchema($data, $key)
    {
        $this->parseDefined($key);

        if (array_key_exists(self::REQUIRED_KEY, $data)) {
            $this->parseRequired(
                $key,
                $data[self::REQUIRED_KEY]
            );
        }

        if (array_key_exists(self::DEFAULT_VALUE, $data)) {
            $this->parseDefault(
                $key,
                $data[self::DEFAULT_VALUE]
            );
        }
    }
977037
public function write($key, $data)
    {
        $this->_cachedData[$key] = $data;
        Cache::set('model-metadata', $this->_cachedData, Cache::TTL_ONE_MONTH);
    }
1296539
public function save(array $data, $key)
    {
        $file = $this->getFilename($key);

        $saved = $this->get($key)->merge($data);

        if (! is_dir(dirname($file))) {
            mkdir(dirname($file), 0777, true);
        }
        file_put_contents($file, json_encode($saved->all()));
    }
1306810
public function update($storageName, $key, array $data)
    {
        if (!isset($this->data[$storageName])) {
            $this->data[$storageName] = [];
        }

        $this->data[$storageName][serialize($key)] = $data;
    }
941850
public function appendData($key, $data)
    {
        $this->_putData($key, $data);

        if ($this->_objectCreation) {
            return $this->_afterAppendDataToNewObject();
        }
        return $this;
    }
1198246
public function setCache($key, $data, $lifetimeInSeconds = false)
    {
        return parent::setCache($this->getHierarchicalKey($key), $data, $lifetimeInSeconds);
    }
1362422
public function save($key, $data)
	{
		$hash = md5($key);
		$cacheFile = $this->getPath().'/'.$hash.'.cache';

		return file_put_contents($cacheFile, serialize($data));
	}