Skip to content

Commit 5b646ad

Browse files
committed
README
1 parent ec17a90 commit 5b646ad

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed

README.md

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,14 @@ return [
3636
其中 `key` 用来设置缓存键的;而 `visit_rate` 用来设置访问频率,单位可以是秒,分,时,天,例如:`1/s`, `10/m`, `98/h`, `100/d` , 也可以是 `100/600` (600 秒内最多 100 次请求)。
3737

3838
### 灵活定制
39-
示例一:若想要针对用户个体做限制,那么 `key` 项可以设为函数,该函数返回新的缓存键值,例如:
39+
示例一:针对用户个体做限制, `key` 的值可以设为函数,该函数返回新的缓存键值,例如:
4040
```
4141
'key' => function($throttle, $request) {
4242
$user_id = $request->session->get('user_id');
4343
return $user_id ;
4444
},
4545
```
46-
实例二:您也可以在回调函数里针对不同控制器和方法定制生成key:
46+
实例二:也可以在回调函数里针对不同控制器和方法定制生成key,中间件会进行转换:
4747
```
4848
'key' => function($throttle, $request) {
4949
return '__CONTROLLER__/__ACTION__/__IP__';
@@ -55,10 +55,24 @@ return [
5555
```
5656
PS:此示例需要本中间件在路由中间件后启用,这样预设的替换功能才会生效。
5757

58-
示例三:允许在闭包内修改本次访问频率
58+
示例三:允许在闭包内修改本次访问频率或临时更换限流策略
5959
```
6060
'key' => function($throttle, $request) {
61-
$throttle->setRate('5/m');
61+
$throttle->setRate('5/m'); // 设置频率
62+
$throttle->setDriverClass(CounterSlider::class);// 设置限流策略
6263
return true;
6364
},
6465
```
66+
67+
## 更新日志
68+
版本 1.1.x 的配置形式完全兼容版本 1.0.x 内容,可以无缝升级。
69+
70+
### 1.1.x 更新
71+
- 添加漏桶限流算法, 令牌桶算法, 计数固定窗口, 滑动窗口共四种限流策略;
72+
- 公共数据改为静态属性,节省内存分配;
73+
- 重构中间件接口,便于扩展更多的限流算法;
74+
- 默认策略使用计数固定窗口的策略;
75+
- 时间取毫秒,某些限流算法需要;
76+
- 只使用一个缓存键完成计数固定窗口,减少缓存读取;
77+
- 开放更多 `set*` 方法,支持链式操作;
78+
- 禁止访问时,改用抛出 `HttpResponseException`

0 commit comments

Comments
 (0)