@carlozancanaro You put an element into it, after a certain amount of time it will be removed, unless fetched, updated or "poked".


@shadowfacts @carlozancanaro I suppose so, the main thing I would need to use it for would be to make things purge themselves after a delay. So it would require a specific interface and callbacks for when the objects are purged. Plus some sort of iteration thing for expired tasks on the ticks.

@gudenau @shadowfacts It looks like Guava has something similar to what you want.


You can add a removal listener to the cache, which isn't mentioned in that answer but is in the javadoc.

bad fiddler on the roof joke 

@carlozancanaro @gudenau

I couldn't help myself

🎵 MapMaker, MapMaker, make me map
🎵 Find me a find, catch me a catch
🎵 MapMaker, MapMaker, look through your impls
🎵And make me a perfect map

bad fiddler on the roof joke 

@shadowfacts @carlozancanaro I have never seen that play.

re: bad fiddler on the roof joke 

@gudenau @carlozancanaro it's a (bad) parody of this song from the musical: https://www.youtube.com/watch?v=59Hj7bp38f8
@gudenau @carlozancanaro Callback is easy, just require that V extend some interface w/ a method that's called on expiry.

You could also keep a Set<V> expired; that's cleared every time step.

To purge expired objects automatically, you'd just have a method that iterates all objects and expires them if necessary, called every time step from a run loop or a worker thread.

@shadowfacts @carlozancanaro Yeah, I was thinking about this wrong. A LinkedList backed thing would probably be best for this, since it would be quick to iterate and once you run out of expired things you know you can stop.

@gudenau @carlozancanaro If you don't need to look things up by keys, yeah that'd work well. Just need to insert new and refreshed objects at the head.

@shadowfacts @gudenau If it's doubly-linked then I don't think it matters which end you insert.

If it's singly linked then you should insert at the tail so you can invalidate items by starting at the head and going forwards until you hit a valid one.

Although if you don't need to do any special processing to invalidate individual entries then you should insert at the head and just drop the entire tail when you read the first invalid item.

@carlozancanaro @shadowfacts You would still need to iterate over all the dropped items to notify them that they where dropped.

@carlozancanaro @shadowfacts Would be a per-use case thing if you did not need to do processing. Might be an interesting paper.

@gudenau @shadowfacts I don't think this is paper worthy. This is pretty basic data structure stuff.

@carlozancanaro @shadowfacts I meant the "drop the head or drop the tale", not a long one mind.

Sign in to participate in the conversation
Mastodon for Tech Folks

This Mastodon instance is for people interested in technology. Discussions aren't limited to technology, because tech folks shouldn't be limited to technology either!