3 ms·
IMO, both examples are bad because they search for the key twice. That’s inefficient and, worse, introduces a concurrency bug. The cached value may expire betw
by Someone 8y ago
IMO, both examples are bad because they search for the key twice.
That’s inefficient and, worse, introduces a concurrency bug. The cached value may expire between the check using ‘contains’ and the call to ‘get’.
A good API would have something akin to C#’s TryGet (https://msdn.microsoft.com/en-us/library/bb347013(v=vs.110).aspx https://msdn.microsoft.com/en-us/library/bb347013(v=vs.110)....).