Skip to content

Commit be176c4

Browse files
author
Mohammed Karim
committed
Ensure that the cache keeps a record of the bucket for the maximum amount of time the bucket may be required.
1 parent 333e26f commit be176c4

1 file changed

Lines changed: 3 additions & 3 deletions

File tree

system/Throttle/Throttler.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ public function check(string $key, int $capacity, int $seconds, int $cost = 1):
143143
// If it hasn't been created, then we'll set it to the maximum
144144
// capacity - 1, and save it to the cache.
145145
$this->cache->save($tokenName, $capacity - $cost, $seconds);
146-
$this->cache->save($tokenName . 'Time', time());
146+
$this->cache->save($tokenName . 'Time', time(), $seconds);
147147

148148
return true;
149149
}
@@ -172,9 +172,9 @@ public function check(string $key, int $capacity, int $seconds, int $cost = 1):
172172
if ($tokens > 0)
173173
{
174174
$response = true;
175+
$this->cache->save($tokenName, $tokens - $cost, $seconds);
176+
$this->cache->save($tokenName . 'Time', time(), $seconds);
175177

176-
$this->cache->save($tokenName, $tokens - $cost, $elapsed);
177-
$this->cache->save($tokenName . 'Time', time());
178178
}
179179

180180
return $response;

0 commit comments

Comments
 (0)