connection->query('SELECT 1 FROM {' . $this->connection->escapeTable($this->table) . '} WHERE collection = :collection AND name = :key AND expire > :now', [ ':collection' => $this->collection, ':key' => $key, ':now' => REQUEST_TIME, ])->fetchField(); } /** * {@inheritdoc} */ public function getMultiple(array $keys) { $values = $this->connection->query( 'SELECT name, value FROM {' . $this->connection->escapeTable($this->table) . '} WHERE expire > :now AND name IN ( :keys[] ) AND collection = :collection', [ ':now' => REQUEST_TIME, ':keys[]' => $keys, ':collection' => $this->collection, ])->fetchAllKeyed(); return array_map([$this->serializer, 'decode'], $values); } /** * {@inheritdoc} */ public function getAll() { $values = $this->connection->query( 'SELECT name, value FROM {' . $this->connection->escapeTable($this->table) . '} WHERE collection = :collection AND expire > :now', [ ':collection' => $this->collection, ':now' => REQUEST_TIME, ])->fetchAllKeyed(); return array_map([$this->serializer, 'decode'], $values); } /** * {@inheritdoc} */ public function setWithExpire($key, $value, $expire) { $this->connection->merge($this->table) ->keys([ 'name' => $key, 'collection' => $this->collection, ]) ->fields([ 'value' => $this->serializer->encode($value), 'expire' => REQUEST_TIME + $expire, ]) ->execute(); } /** * {@inheritdoc} */ public function setWithExpireIfNotExists($key, $value, $expire) { $result = $this->connection->merge($this->table) ->insertFields([ 'collection' => $this->collection, 'name' => $key, 'value' => $this->serializer->encode($value), 'expire' => REQUEST_TIME + $expire, ]) ->condition('collection', $this->collection) ->condition('name', $key) ->execute(); return $result == Merge::STATUS_INSERT; } /** * {@inheritdoc} */ public function setMultipleWithExpire(array $data, $expire) { foreach ($data as $key => $value) { $this->setWithExpire($key, $value, $expire); } } /** * {@inheritdoc} */ public function deleteMultiple(array $keys) { parent::deleteMultiple($keys); } }