protected function DatabaseRawBackend::doCounter in Supercache 8
Same name and namespace in other branches
- 2.0.x src/Cache/DatabaseRawBackend.php \Drupal\supercache\Cache\DatabaseRawBackend::doCounter()
doCounter: if the $cid already exists and is not numeric should throw an exception. If it does not exist, should be populated with the default value.
Parameters
mixed $cid :
mixed $increment :
mixed $default :
Throws
\Exception
1 call to DatabaseRawBackend::doCounter()
- DatabaseRawBackend::counter in src/
Cache/ DatabaseRawBackend.php - Add an increment (can be negative) to the stored cache data. Only works for stored numeric data.
File
- src/
Cache/ DatabaseRawBackend.php, line 383 - Contains \Drupal\supercache\Cache\DatabaseRawBackend.
Class
- DatabaseRawBackend
- Defines a default cache implementation.
Namespace
Drupal\supercache\CacheCode
protected function doCounter($cid, $increment, $default = 0) {
$query = $this->connection
->update($this->bin);
$query
->condition('cid', $cid);
$query
->condition('data_int', NULL, 'IS NOT NULL');
$query
->expression('data_int', "data_int + {$increment}");
$result = 0;
try {
$result = $query
->execute();
} catch (\Exception $e) {
}
if ($result == 0) {
// Make sure the item does not exist before doing a set...
$query = $this->connection
->select($this->bin);
$query
->addField($this->bin, 'cid');
$query
->condition('cid', $this
->normalizeCid($cid));
$count = count($query
->execute()
->fetchAll());
if ($count == 1) {
throw new \Exception("Counter failed.");
}
// Set the default value...
$this
->counterSet($cid, $default);
}
}