title: How can I consolidate deferred/delayed calls in Objective-C?
body: <p>I'd like to ensure that certain maintenance tasks are executed "eventually".  For example, after I detect that some resources might no longer be used in a cache, I might call:</p>
  
  <p>[self performSelector:@selector(cleanupCache) withObject:nil afterDelay:0.5];</p>
  
  <p>However, there might be numerous places where I detect this, and I don't want to be calling cleanupCache continuously. I'd like to consolidate multiple calls to cleanupCache so that we only periodically get ONE call to cleanupCache.  </p>
  
  <p>Here's what I've come up with do to this-- is this the best way?  </p>
  
  <p>[NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(cleanupCache) object:nil];
  [self performSelector:@selector(cleanupCache) withObject:nil afterDelay:0.5];</p>