title: Can I trust objectForKey right after setObject in NSCache?
body: <p>Considering this sample code (cache is an instance of NSCache):</p>
  
  <pre><code>- (id)objFromCache
  {
      if ([cache objectForKey:@"myObject"] == nil)
          [cache setObject:[self generateObject] forKey:@"myObject"];
  
      return [cache objectForKey:@"myObject"];
  }
  </code></pre>
  
  <p>Should I trust this code? I mean, will <code>objectForKey:@"myObject"</code> ever return nil right after <code>setObject:forKey:@"myObject"</code>? If so, whould I change <code>if</code> to <code>while</code>?</p>
  
  <p>What's the best way to handle this situation? Thanks!</p>