Releases: benjick/pg-ratelimit
Releases · benjick/pg-ratelimit
v0.2.0
In-memory block strategy
Cache blocked keys in-process to skip DB round trips for repeated rate-limited requests. Enable with inMemoryBlock: true.
- Significant latency and throughput improvements under load
maxBlockedKeysoption (default: 10,000) caps cache size with automatic expired-entry sweeping- Negative-rate calls and
resetUsedTokens()bypass/clear the cache automatically InMemoryBlockConfigandDurableConfigdiscriminated union types -maxBlockedKeysis a type error unlessinMemoryBlock: true- Benchmark package comparing both modes
Bug fixes
- Fixed all internal doc links (absolute paths were missing
/pg-ratelimitbase, causing 404s)
Full changelog: v0.1.0...v0.2.0
v0.1.0
Initial release of pg-ratelimit — PostgreSQL-backed rate limiting for Node.js.
Added
- Three rate limiting algorithms: fixed window, sliding window, and token bucket
limit()- check and consume rate limit tokensblockUntilReady()- poll until success or timeoutgetRemaining()- read remaining quota without consumingresetUsedTokens()- full reset of a key's quota- Two-table design: ephemeral (UNLOGGED) for speed, durable (logged) for crash safety
- Weighted costs via
rateoption - Negative rate for token refunds
- Probabilistic inline cleanup of expired rows
- Injectable clock for deterministic testing
TABLE_SQLexport for manual migration- Auto-migration with
CREATE TABLE IF NOT EXISTS(disable viaPG_RATELIMIT_DISABLE_AUTO_MIGRATE) synchronousCommitoption for durable mode
npm install pg-ratelimit pg