ttl_cache icon indicating copy to clipboard operation
ttl_cache copied to clipboard

Support a TtlCacheSet

Open mathstuf opened this issue 8 years ago • 5 comments

Sometimes just existence is necessary, so a TtlCacheSet would be a nice addition.

mathstuf avatar Oct 25 '17 17:10 mathstuf

You can just set the value to ().

type TtlCacheSet<K> = TtlCache<K, ()>

Maybe this could be a pub type in this crate though since it's common functionality.

leoschwarz avatar Nov 17 '17 21:11 leoschwarz

Well, there are some additional methods that may make sense on TtlCacheSet that (might?) not make as much on TtlCacheMap: intersection, union, etc.

mathstuf avatar Nov 21 '17 21:11 mathstuf

I see two ways how this could be done:

  • Implement a new struct, wrapping TtlCache<K, ()> and implementing all relevant methods.
  • Or actually implement set operations on the TtlCache and document that when there is a duplicate value for a key, the value from the one on the left hand (or "self" or whatever it ends up being in the api) side is going to be used.

One advantage of the first one is that it's cleaner. Users don't have to bother inserting tuples with an empty tuple as the value like they would have if using TtlCache like I suggested before.

Main question obviously being if you really need set operations on this struct in the first place?

leoschwarz avatar Nov 23 '17 20:11 leoschwarz

Well, my need is less now (I actually needed to store a bool, not a singleton), but the request could still make sense for someone else.

mathstuf avatar Nov 29 '17 21:11 mathstuf

Next time I get a chance to sit down with the library I will implement TtlSet as TtlCache as @leoschwarz suggested. This is the same way HashSet in the StdLib is implemented

stusmall avatar Apr 07 '18 17:04 stusmall