public function set($entryIdentifier, $data, array $tags = [], $lifetime = null)
{
$this->connect();
if (!$this->cache instanceof FrontendInterface) {
throw new Exception('No cache frontend has been set yet via setCache().', 1259515600);
}
if (!is_string($data)) {
throw new InvalidDataException('The specified data is of type "' . gettype($data) . '" but a string is expected.', 1259515601);
}
$this->remove($entryIdentifier);
$lifetime = $lifetime === null ? $this->defaultLifetime : $lifetime;
// Convert binary data into hexadecimal representation,
// because it is not allowed to store null bytes in PostgreSQL.
if ($this->pdoDriver === 'pgsql') {
$data = bin2hex($data);
}
$statementHandle = $this->databaseHandle->prepare('INSERT INTO "cache" ("identifier", "context", "cache", "created", "lifetime", "content") VALUES (?, ?, ?, ?, ?, ?)');
$result = $statementHandle->execute([$entryIdentifier, md5($this->environmentConfiguration->getApplicationIdentifier()), $this->cacheIdentifier, time(), $lifetime, $data]);
if ($result === false) {
throw new Exception('The cache entry "' . $entryIdentifier . '" could not be written.', 1259530791);
}
$statementHandle = $this->databaseHandle->prepare('INSERT INTO "tags" ("identifier", "context", "cache", "tag") VALUES (?, ?, ?, ?)');
foreach ($tags as $tag) {
$result = $statementHandle->execute([$entryIdentifier, md5($this->environmentConfiguration->getApplicationIdentifier()), $this->cacheIdentifier, $tag]);
if ($result === false) {
throw new Exception('The tag "' . $tag . ' for cache entry "' . $entryIdentifier . '" could not be written.', 1259530751);
}
}
}