Skip to content

Commit

Permalink
Add warning log for rate limit cache size exceedance instead of remov…
Browse files Browse the repository at this point in the history
…ing oldest timestamp
  • Loading branch information
javier-villatoro committed Aug 8, 2024
1 parent b81d01e commit 6268f16
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/Http/Middleware/LeverRateStore.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Bluelightco\LeverPhp\Http\Middleware;

use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\Log;
use Spatie\GuzzleRateLimiterMiddleware\Store;

/**
Expand Down Expand Up @@ -46,8 +47,8 @@ public function push(int $timestamp, int $limit)

// calculate the size of the data
if ($this->getCacheSize($data) > $this->maxCacheSize) {
// If the size exceeds the maxCacheSize, remove the oldest timestamp
array_shift($data);
// Log a warning instead of removing the oldest timestamp
Log::warning("Rate limit exceeded: Cache size for '{$this->cacheKey}' has exceeded the configured limit of {$this->maxCacheSize} bytes.");
}

// Store the updated data back into the cache
Expand Down

0 comments on commit 6268f16

Please sign in to comment.