Guides
Cleanup
Configure and control stale-state cleanup for every provider.
Provider builders start stale-state cleanup by default. Cleanup is separate from lazy bucket expiration performed by reads and admission operations.

Configure startup
use std::time::Duration;
use trypema::RateLimiterBuilder;
use trypema::local::LocalRateLimiterProvider;
let provider = LocalRateLimiterProvider::builder()
.stale_after(Duration::from_secs(600))
.cleanup_interval(Duration::from_secs(30))
.disable_cleanup()
.build()
.unwrap();
stale_after is the inactivity period before a key becomes cleanup-eligible;
cleanup_interval is how often the provider scans. Their defaults are 10 minutes and 30 seconds.
disable_cleanup()prevents automatic startup.enable_cleanup()enables automatic startup.cleanup_enabled(bool)supports runtime-conditional configuration.
Control after construction
All providers expose idempotent controls:
provider.start_cleanup_loop();
provider.stop_cleanup_loop();
Hybrid synchronization remains mandatory and independent of optional stale-state cleanup.
Cleanup matters most for long-running services and large or changing key spaces.

