Documentation ¶
Index ¶
Constants ¶
const (
// DrainPerSecond is the number of tokens per second drained from each bucket
DrainPerSecond = 1000000000
)
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Cache ¶
type Cache struct { MaxEntries int // contains filtered or unexported fields }
Cache is a size-limited hash-map implementation of the leaky bucket rate-limiting algorithm. Entries are roughly 78 bytes each.
func (*Cache) Put ¶
Put attempts to add quantity tokens into the bucket referred to by a uint64 key that has a size limit of limit tokens. Return the current number of tokens in the bucket, whether the key already existed, and whether there was enough room in the bucket to add the requested number of tokens.
func (*Cache) PutString ¶
PutString attempt to add quantity tokens into the bucket referred to the string ks that has a size limit of limit tokens. Return the current number of tokens in the bucket, whether the key already existed, and whether there was enough room in the bucket to add the requested number of tokens.