public function decrement($key, $offset = 1, $initial = 0, $expire = 0)
{
if ($offset <= 0 || $initial < 0) {
return false;
}
// get existing value (from real cache or memory) so we know what to
// increment in memory (where we may not have anything yet, so we should
// adjust our initial value to what's already in real cache)
$value = $this->get($key);
if ($value === false) {
$value = $initial + $offset;
}
if (!is_numeric($value) || !is_numeric($offset)) {
return false;
}
// store the value in memory, so that when we ask for it again later
// in this same request, we get the value we just set
$value = max(0, $value - $offset);
$success = $this->local->set($key, $value, $expire);
if ($success === false) {
return false;
}
$this->defer->decrement($key, $offset, $initial, $expire);
return $value;
}