/** * {@inheritdoc} * * @param int|string $keyName * @param string $content * @param int $lifetime * @param bool $stopBuffer * * @throws Exception */ public function save($keyName = null, $content = null, $lifetime = null, $stopBuffer = true) { if ($keyName === null) { $prefixedKey = $this->_lastKey; } else { $prefixedKey = $this->getPrefixedIdentifier($keyName); } if (!$prefixedKey) { throw new Exception('The cache must be started first'); } if (null === $content) { $cachedContent = $this->_frontend->getContent(); } else { $cachedContent = $content; } if (null === $lifetime) { $lifetime = $this->_lastLifetime; if (null === $lifetime) { $lifetime = $this->_frontend->getLifetime(); } } $aKey = $this->buildKey($prefixedKey); if (is_numeric($cachedContent)) { $bins = ['value' => $cachedContent]; } else { $bins = ['value' => $this->_frontend->beforeStore($cachedContent)]; } $status = $this->db->put($aKey, $bins, $lifetime, [AerospikeDb::OPT_POLICY_KEY => AerospikeDb::POLICY_KEY_SEND]); if (AerospikeDb::OK != $status) { throw new Exception(sprintf('Failed storing data in Aerospike: %s', $this->db->error()), $this->db->errorno()); } if (true === $stopBuffer) { $this->_frontend->stop(); } if (true === $this->_frontend->isBuffering()) { echo $cachedContent; } $this->_started = false; }