-
Notifications
You must be signed in to change notification settings - Fork 6
Open
Labels
choreNot an immediate requirement but its good to haveNot an immediate requirement but its good to haveenhancementNew feature or requestNew feature or requestgood first issueGood for newcomersGood for newcomers
Description
Description
Implement a background worker service that runs on a schedule to clean up expired OTP records from the storage layer (e.g., in-memory cache, database, or Redis). This helps prevent memory bloat, stale authentication attempts, and improves system hygiene.
Key Requirements
- Periodically check for expired OTPs
- Delete OTPs that have surpassed their expiration time
- Should not block main application threads
- Configurable cleanup interval (e.g., every 5 minutes)
- Logging of cleanup activity (e.g., number of entries removed)
- Gracefully handles storage unavailability or exceptions
- Should support dependency injection for OTPManager Service
Suggested Implementation
- Create a hosted service: OtpCleanupWorker : BackgroundService
- Inject an IOtpStoreService with a method like RemoveExpiredOtpsAsync()
- Use ILogger to log activity
- Place the worker registration inside your Startup.cs or Program.cs using
services.AddHostedService<OtpCleanupWorker>();
Why This Is Needed
Unattended OTP records can clutter memory and degrade performance. This service ensures that the system remains lightweight, secure, and performant by cleaning expired tokens.
Feel free to drop a comment if you require any clarifications
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
choreNot an immediate requirement but its good to haveNot an immediate requirement but its good to haveenhancementNew feature or requestNew feature or requestgood first issueGood for newcomersGood for newcomers