Documentation
¶
Overview ¶
Package memory implements explicit single-process fixed-window rate limiting. It never evicts live quotas or becomes an automatic Redis failure fallback.
Index ¶
- type Backend
- func (b *Backend) ClearRateLimit(ctx context.Context, key ratelimit.Key) (bool, error)
- func (b *Backend) Close() error
- func (*Backend) FoundryAdapter(frameworkadapter.Seal)
- func (b *Backend) PeekRateLimit(ctx context.Context, key ratelimit.Key, limit ratelimit.Limit, cost uint32) (ratelimit.Decision, error)
- func (b *Backend) RateLimit(ctx context.Context, key ratelimit.Key, limit ratelimit.Limit, cost uint32) (ratelimit.Decision, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Backend ¶
type Backend struct {
// contains filtered or unexported fields
}
Backend owns at most maxEntries live buckets. Key sizes and each bucket's state are bounded. Clock.Now must return promptly. Hot buckets are O(1); expired buckets are reclaimed lazily on access and, when a new bucket needs capacity, from an expiry-ordered heap. A backward clock reading is clamped to the latest reading already observed, so it can neither reopen old quota nor fail.
func New ¶
New creates a bounded in-memory backend using source as its clock; capacity must be positive.
func (*Backend) ClearRateLimit ¶
ClearRateLimit removes the key's live bucket; true means one existed.
func (*Backend) Close ¶
Close releases this local authority. Stop its callers first; no background work is started by this adapter or the borrowing Store.
func (*Backend) FoundryAdapter ¶
func (*Backend) FoundryAdapter(frameworkadapter.Seal)
FoundryAdapter marks the backend as a framework-owned adapter.