Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Aging Objects in a Collection [closed]

I want to be able to age objects in a Collection.

For example I could put strings in a HashSet.

  1. I would like timestamps associated of when the String was put in the HashSet.
  2. I would like String older than say time X to be dropped from the HashSet.
  3. I would like to be able to say "touch" a string and update the time to when it was inserted in the Collection.

So I can accomplish this by keeping track of each String and then running a house cleaning Thread and purging String from the Collection if it is older than a certain time quantum.

However I am looking for:

  1. Either a Clever way to do this.
  2. An existing open-source java component which accomplishes this.

Thanks.

like image 289
user1172468 Avatar asked Jun 17 '26 23:06

user1172468


1 Answers

Sounds like you need a cache. Either try CacheBuilder (see Caches Explained) from Guava or EhCache.

like image 73
Tomasz Nurkiewicz Avatar answered Jun 20 '26 11:06

Tomasz Nurkiewicz



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!