NexusForce 1.0.0
A rigorously engineered full-stack C++ backend library.
载入中...
搜索中...
未找到
neforce::http::token_bucket_limiter类 参考

令牌桶限流管理器 更多...

#include <rate_limiter.hpp>

Public 成员函数

bool allow (const string &key, double rate=0.0, double burst=0.0)
 检查并消耗令牌
void set_default_rate (double rate)
 设置默认的令牌补充速率
void set_default_burst (double burst)
 设置默认的桶容量
size_t size () const
 获取桶数量
void cleanup_expired (seconds max_age=seconds{300})
 清理过期的桶

详细描述

令牌桶限流管理器

管理多个客户端/路由的令牌桶,支持LRU淘汰和批量清理。

在文件 rate_limiter.hpp86 行定义.

成员函数说明

◆ allow()

bool neforce::http::token_bucket_limiter::allow ( const string & key,
double rate = 0.0,
double burst = 0.0 )

检查并消耗令牌

参数
key客户端标识(如IP或IP+路由)
rate每秒补充令牌数(<=0 使用默认)
burst桶容量(<=0 使用默认)
返回
允许通过返回true,被限制返回false

◆ cleanup_expired()

void neforce::http::token_bucket_limiter::cleanup_expired ( seconds max_age = seconds{300})

清理过期的桶

参数
max_age超过此时间未使用的桶将被移除

该类的文档由以下文件生成: