# README
Periodic Cleaning: true | false Check before Get: true | false Cleaning before Get: clean all | clean current | false Cleaning interval: fixed | adaptive
Implement 1: Periodic Cleaning and Expiry Check on Get
Description: Clean the map at fixed intervals. Each get request will check if the token has expired and delete it if it has. Performance: Clean: Performed at fixed intervals, which can be computationally expensive if the map is large. Get: Each get operation includes an additional check for expiration, potentially slowing down the get operation. Memory Usage: Memory usage remains consistent since expired tokens are regularly cleaned, preventing memory bloat. Pros: Ensures that tokens are always current, providing accurate data on get. Cons: Both clean and get operations can be computationally expensive.
Implement 2: Periodic Cleaning Without Expiry Check on Get
Description: Clean the map at fixed intervals. The get operation does not check for expiration. Performance: Clean: Same as Implement 1, performed at fixed intervals. Get: Faster since it doesn't involve checking for expiration. Memory Usage: Memory usage can temporarily increase since expired tokens are not immediately removed during get operations but will be cleaned up at the next interval. Pros: Faster get operations. Cons: Potential memory bloat between clean intervals and possible retrieval of expired tokens.
Implement 3: Clean Before Each Get Request
Description: Perform a cleaning operation before each get request to remove expired tokens. Performance: Clean: Clean is performed frequently, potentially on each get, which can be computationally expensive. Get: Includes the cleaning operation, making it slower. Memory Usage: Memory usage is kept under control since expired tokens are removed frequently. Pros: Ensures that the map is always up-to-date and free of expired tokens. Cons: High computational overhead for frequent cleaning operations.
Implement 4: Lazy Deletion
Description: Check for expiration only when accessing the token. Expired tokens are marked for deletion and removed during future accesses or during periodic cleanup. Performance: Clean: Periodic, but less frequent or less intensive because tokens are also cleaned up lazily during accesses. Get: Each get operation includes an expiration check but does not always involve immediate removal. Memory Usage: Similar to Implement 1, but with potential for slightly higher usage if clean operations are infrequent. Pros: Balances get performance and memory management by spreading the cleanup load. Cons: Slight delay in memory cleanup.
Implement 5: Time-Ordered Data Structure
Description: Use a data structure like a priority queue (min-heap) or an ordered map that keeps tokens sorted by expiration time. Periodic cleaning can be optimized to only remove expired tokens efficiently. Performance: Clean: Efficient, as it directly accesses the oldest (and potentially expired) tokens first. Get: Fast, as it simply retrieves the token and performs an expiration check. Memory Usage: Well-managed, as expired tokens are quickly and efficiently cleaned. Pros: Efficient cleanup and retrieval operations. Cons: Complexity of maintaining the data structure.
Implement 6: Expiry-based Partitioning
Description: Partition tokens into different segments based on their expiration times (e.g., buckets for each minute or hour). Clean and access operations are optimized within smaller partitions. Performance: Clean: Targeted, as only relevant partitions are cleaned. Get: Potentially faster, as fewer tokens are checked within each partition. Memory Usage: Efficient, as expired tokens are cleaned more effectively within partitions. Pros: Improved performance for large datasets by reducing the scope of clean and get operations. Cons: Additional complexity in managing partitions.
Implement 7: Hybrid Approach with Adaptive Cleaning
Description: Combine multiple strategies with an adaptive cleaning mechanism that adjusts based on load and usage patterns. Performance: Clean: Adaptive, becoming more frequent during high usage periods and less frequent during low usage. Get: Balanced, as expiration checks are optimized based on the current load. Memory Usage: Well-managed, as the system adapts to current usage patterns. Pros: Dynamically balances performance and memory usage. Cons: Increased complexity in implementation and tuning.