How to check if a key exists in a MemoryCache
14,265
Use bool Contains(string key, string regionName)
method.
MSDN:
Determines whether a cache entry exists in the cache. Return Value Type: System.Boolean true if the cache contains a cache entry whose key matches key; otherwise, false.
MemoryCache.Contains Method (String, String), MSDN
Comments
-
that guy over there almost 2 years
I need to check if a key is present in a MemoryCache. However there is no Keys collection or something similar available.
I do not need the object associated with the key only a true or false if a certain key is present.
I know I can try a .Get(key) but I do not need the object. Is this the only way?