C
C#9mo 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
tera9mo ago
you can use tryget and discard the value if you really need it
Camster
CamsterOP9mo ago
True, I suppose I could do that. Doesn't seem very efficient, but that would work
reflectronic
reflectronic9mo ago
it is identical the implementation of ContainsKey on ConcurrentDictionary is TryGetValue(key, out _) (and, MemoryCache is essentially a clumsy wrapper over ConcurrentDictionary)
Camster
CamsterOP9mo ago
Okay, cool. Funny, I'm using MemoryCach to store ConcurrentDictionaries 😄
reflectronic
reflectronic9mo 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
CamsterOP9mo 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
reflectronic9mo 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