title: NSCache does not work
body: <p>I'm writing an app that needs store a few images in cache. I'm trying to do it with NSCache and the code seems to be well but don't save the images in cache. I have this code:</p>
  
  <p>cache is global, declared in .h:     <code>NSCache *cache;</code></p>
  
  <pre><code>-(UIImage *)buscarEnCache:(UsersController *)auxiliarStruct{
      UIImage *image;
      [[cache alloc] init];
  
      NSLog(@"cache: %i", [cache countLimit]);
      if ([cache countLimit] &gt; 0) { //if [cache countLimit]&gt;0, it means that cache isn't empty and this is executed
          if ([cache objectForKey:auxiliarStruct.thumb]){    
              image = [cache objectForKey:auxiliarStruct.thumb];
          }else{ //IF isnt't cached, is saved
              NSString *imageURLString = [NSString stringWithFormat:@"http://mydomain.com/%@",auxiliarStruct.thumb];
              NSURL *imageURL = [NSURL URLWithString:imageURLString];
              NSData * imageData = [NSData dataWithContentsOfURL:imageURL];
              image = [UIImage imageWithData:imageData];
              [cache setObject:image forKey:auxiliarStruct.thumb];
          }        
      }else{ //This if is executed when cache is empty. IS ALWAYS EXECUTED BECAUSE FIRST IF DOESN'T WORKS CORRECTLY
          NSString *imageURLString = [NSString stringWithFormat:@"http://mydomain.com/%@",auxiliarStruct.thumb];
          NSURL *imageURL = [NSURL URLWithString:imageURLString];
          NSData * imageData = [NSData dataWithContentsOfURL:imageURL];
          image = [UIImage imageWithData:imageData];
          [cache setObject:image forKey:auxiliarStruct.thumb];
      }
      return image;
  }
  </code></pre>
  
  <p>This function is called in other function with this:</p>
  
  <pre><code>      UIImage *image = [self buscarEnCache:auxiliarStruct];
  </code></pre>
  
  <p>This works because the image is displayed on screen but isn't saved in cache, the line that I think fails is: </p>
  
  <p><code>[cache setObject:image forKey:auxiliarStruct.thumb]; //auxiliarStruct.thumb is the name of the image</code></p>
  
  <p>Someone knows why cache doesn't work?? Thanks!!</p>
  
  <p>ps: sorry for my english, I know is bad</p>