Support a TtlCacheSet
Sometimes just existence is necessary, so a TtlCacheSet would be a nice addition.
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.
Well, there are some additional methods that may make sense on TtlCacheSet that (might?) not make as much on TtlCacheMap: intersection, union, etc.
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?
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.
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