I want to store in a queue, datastructure does not matter, only the elements that I have inserted within say last 5 minutes from current time. Anything older should get removed
In what language? Is the queue persistent or in-memory?
If you need this behavior in Java, you can use a DelayedQueue, and have a separate thread calling queue.take()
continuously in a tight loop to drain out expired items. queue.size()
will then give you the size of remaining unexpired items in the queue. This requires that the items you put in the DelayedQueue implement the Delayed interface and return the value 5 minutes to the .getDelay()
method.