Guides

Cleanup

How Trypema removes stale limiter state and when you need to start cleanup manually.

Trypema can clean up stale limiter state in the background.

Two setup paths, two cleanup behaviors

Builder path

build() starts the cleanup loop automatically.

This is the easiest path for most applications:

  • RateLimiter::builder().build() for local-only builds
  • RateLimiter::builder(connection_manager).build() for Redis-enabled builds

Explicit options path

RateLimiter::new(...) does not start cleanup automatically.

If you construct the limiter this way and want background cleanup, call:

rl.run_cleanup_loop();

Why cleanup matters

Cleanup removes stale state so inactive keys do not accumulate forever.

This matters most for:

  • long-running services
  • large or constantly changing key spaces
  • Redis and hybrid deployments where stale remote state should also be pruned

Practical guidance

  • Use the builder unless you need explicit options.
  • If you use new(...), decide deliberately whether you want background cleanup and start it yourself when you do.