Skip to content
This repository was archived by the owner on Apr 19, 2024. It is now read-only.

Commit 08f8411

Browse files
committed
Requests over remaining shouldn't change remaining
REP-937 Previously there was a disparity between uncached and cached limits when requesting limit L > remaining R. * When uncached, R would be set to 0 and OverLimit returned * When cached, R would be remain R and OverLimit returned Now, in both instances, R remains unmodified and OverLimit is returned for that requested limit.
1 parent bcdfe73 commit 08f8411

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

algorithms.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ func tokenBucket(c cache.Cache, r *RateLimitReq) (*RateLimitResp, error) {
7777
// Client could be requesting that we always return OVER_LIMIT
7878
if r.Hits > r.Limit {
7979
status.Status = Status_OVER_LIMIT
80-
status.Remaining = 0
80+
status.Remaining = r.Limit
8181
}
8282

8383
c.Add(r.HashKey(), status, expire)

cache/lru.go

+4
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,10 @@ func (c *LRUCache) Size() int {
146146
return c.ll.Len()
147147
}
148148

149+
func (c *LRUCache) Stats(_ bool) Stats {
150+
return c.stats
151+
}
152+
149153
// Update the expiration time for the key
150154
func (c *LRUCache) UpdateExpiration(key Key, expireAt int64) bool {
151155
if ele, hit := c.cache[key]; hit {

0 commit comments

Comments
 (0)