C
C#8mo ago
Camster

✅ IMemoryCache missing Contains?

Why is there no Contains in IMemoryCache? I feel like I'm missing something really obvious here.
No description
7 Replies
tera
tera8mo ago
you can use tryget and discard the value if you really need it
Camster
CamsterOP8mo ago
True, I suppose I could do that. Doesn't seem very efficient, but that would work
reflectronic
reflectronic8mo ago
it is identical the implementation of ContainsKey on ConcurrentDictionary is TryGetValue(key, out _) (and, MemoryCache is essentially a clumsy wrapper over ConcurrentDictionary)
Camster
CamsterOP8mo ago
Okay, cool. Funny, I'm using MemoryCach to store ConcurrentDictionaries 😄
reflectronic
reflectronic8mo ago
i think it isn't provided because it does not really make sense for a cache what would you do with the return value of Contains
Camster
CamsterOP8mo ago
I see what you mean. I was confused because when I google it, everything says "just use contains", but I can't find contains. Nonetheless, I think I can see how I can just use TryGetValue or GetOrCreate to do what needs to be done. I suppose that check isn't necessary Thank you for your help 🙂
reflectronic
reflectronic8mo ago
right. the useful, atomic, operations are already provided. Contains used in a naive way is pretty much always a race condition
Want results from more Discord servers?
Add your server