On Wed, Jul 19, 2017 at 3:22 PM, Rajanikanth Jammalamadaka <
rajanika...@gmail.com> wrote:

> Does somebody have a recommendation for an expiring dict? If I have to
> write my own, is there a way to avoid iterating over all the keys to delete
> the expired entries?
>
>
>
It's not expensive to get a read lock and iterate. That's what I usually do.

If you have few enough records you could kick off a goroutine for each with
a timeout that would then delete the key. Probably a bad idea, but it could
work.

You could put every newly-added key into a slice, and have an infinite loop
which sleeps, reads from the list and purges anything expired and truncates
the slice.

You can simply have the "get" function that pulls things out check the
expiration and, if expired, delete it and return no result. This would
bloat for unused keys, but you could combine it with one of the solutions
above, or an infinite loop that grabs a random key every second (or less)
to help prune.

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to