For a simple example, I would like to have a list of strings. Each item in the list should “expire” 5 minutes after adding it to the list. Although it may not be a simple, built-in way to do this, I would like to get a data structure whose API seems to be "just working."
You can use it as follows:
var now = DateTime.now(); var list = new ListWithTTL<string>(); list.add("Bob", now); list.add("Joe", now.AddMinutes(1)); list.add("Tom", now.AddMinutes(2)); list.add("Tim", now.AddMinutes(2));
Inspecting the items will immediately lead to
["Bob", "Joe", "Tom", "Tim"]
In a few minutes he should give
["Tom", "Tim"]
In the end, the list should be empty.
Larsenal
source share