Skip to content

Commit 0c4380e

Browse files
committed
reduce cache durations
1 parent 16024fd commit 0c4380e

File tree

5 files changed

+12
-11
lines changed

5 files changed

+12
-11
lines changed

docs/complete-guide.md

+4-3
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,8 @@ echo "BOUNCER_KEY=`docker-compose exec crowdsec /usr/local/bin/cscli bouncers ad
7777
Init the `composer.json` and download the `crowdsec/bouncer` library (just wait a short moment for the first docker image build)
7878

7979
```bash
80-
docker-compose run app composer init --no-interaction --require crowdsec/bouncer:^0
80+
docker-compose run app composer init --no-interaction
81+
docker-compose run app composer require crowdsec/bouncer
8182
docker-compose run app composer install
8283
```
8384

@@ -160,7 +161,7 @@ docker-compose run app php check-ip.php 2.3.4.5
160161

161162
For this IP, the cache system will never ask LAPI anymore for the duration of the decision.
162163

163-
Note: By default, a "bypass" decision is stored in the cache for 10 min. You can change this duration while instantiating the library.
164+
Note: By default, a "bypass" decision is stored in the cache for 1 min. You can change this duration while instantiating the library.
164165

165166
Don't forget to restart the crowdsec container before continuing :-)
166167

@@ -410,7 +411,7 @@ docker-compose run app php check-ip.php 2.3.4.5
410411

411412
> Even if CrowdSec LAPI is down, your bouncer can get the correct information.
412413
413-
To stay protected, you have to call the **refresh-cache.php** script periodically (ie each 15minutes). To do so you can use `crontab` like systems but we will not see that in this guide.
414+
To stay protected, you have to call the **refresh-cache.php** script periodically (ie each 30seconds). To do so you can use `crontab` like systems but we will not see that in this guide.
414415

415416
## Enjoy implementing nice PHP bouncers!
416417

docs/configuration-reference.md

+3-2
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,9 @@
2020
// Optional. Cap the remediation to the selected one. Select from 'bypass' (minimum remediation), 'captcha' or 'ban' (maximum remediation). Defaults to 'ban'.
2121
'max_remediation_level'=> 'ban',
2222

23-
// Optional. Set the duration we keep in cache the fact that an IP is clean. In seconds. Defaults to 600 (10 minutes).
24-
'cache_expiration_for_clean_ip'=> '600',
23+
24+
// Optional. Set the duration we keep in cache the fact that an IP is clean. In seconds. Defaults to 60 (1 minute).
25+
'cache_expiration_for_clean_ip'=> '60',
2526
]
2627
$cacheAdapter = (...)
2728
$bouncer = new Bouncer();

src/ApiCache.php

+3-2
Original file line numberDiff line numberDiff line change
@@ -402,8 +402,9 @@ public function get(string $ip): string
402402
}
403403

404404
if ($this->adapter->hasItem($ip)) {
405-
$this->logger->debug("Cache hit for IP: $ip");
406-
return $this->hit($ip);
405+
$remediation = $this->hit($ip);
406+
$this->logger->debug("Cache hit for IP: $ip: $remediation");
407+
return $remediation;
407408
} else {
408409
$this->logger->debug("Cache miss for IP: $ip");
409410
return $this->miss($ip);

src/Bouncer.php

-2
Original file line numberDiff line numberDiff line change
@@ -135,8 +135,6 @@ public function pruneCache(): bool
135135
return $this->apiCache->clear();
136136
}
137137

138-
139-
140138
/**
141139
* Browse the remediations cache.
142140
*/

src/Constants.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ class Constants
2424
/** @var int The timeout when calling LAPI or CAPI */
2525
public const API_TIMEOUT = 1;
2626

27-
/** @var int The duration we keep a clean IP in cache 600s = 10m */
28-
public const CACHE_EXPIRATION_FOR_CLEAN_IP = 600; // TODO P3 check the correct bypass duration
27+
/** @var int The duration we keep a clean IP in cache 60s = 1m */
28+
public const CACHE_EXPIRATION_FOR_CLEAN_IP = 60;
2929

3030
/** @var string The ban remediation */
3131
public const REMEDIATION_BAN = 'ban';

0 commit comments

Comments
 (0)