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?
Cache memory increases a computer's performance. The cache memory is located very close to the CPU, either on the CPU chip itself or on the motherboard in the immediate vicinity of the CPU and connected by a dedicated data bus.
MemoryCache implements IDisposable so you should call Dispose before replacing the old instance.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With