Skip to content

Commit

Permalink
Added EGOUICacheCancel()
Browse files Browse the repository at this point in the history
  • Loading branch information
shnhrrsn committed Jan 6, 2010
1 parent 72698ff commit 352ab72
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 10 deletions.
3 changes: 3 additions & 0 deletions EGOUICache.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@

UIImage* EGOUICachedDrawing(id target, SEL selector, CGRect rect, NSString* salt);

// Should be called from the method calling EGOUICachedDrawing, cancels 1 level
void EGOUICacheCancel();

// Sets the maximum length the cache will persist for.
// Important: This does not guarantee cache will persist for this period, since caches can be cleared at any time.
void EGOUICacheSetCacheTimeoutInterval(NSTimeInterval cacheTimeoutInterval);
Expand Down
28 changes: 18 additions & 10 deletions EGOUICache.m
Original file line number Diff line number Diff line change
Expand Up @@ -62,20 +62,28 @@
[invocation setSelector:selector];
[invocation setArgument:&adjustedRect atIndex:2];
[invocation invokeWithTarget:target];

CGImageRef cgImage = CGBitmapContextCreateImage(imageContext);
UIGraphicsPopContext();
CGContextRelease(imageContext);

image = [UIImage imageWithCGImage:cgImage];
CGImageRelease(cgImage);

[[EGOCache currentCache] setImage:image forKey:key withTimeoutInterval:_cacheTimeoutInterval];

return image;
if(!_cancelCache) {
CGImageRef cgImage = CGBitmapContextCreateImage(imageContext);
UIGraphicsPopContext();
CGContextRelease(imageContext);

image = [UIImage imageWithCGImage:cgImage];
CGImageRelease(cgImage);

[[EGOCache currentCache] setImage:image forKey:key withTimeoutInterval:_cacheTimeoutInterval];
return image;
} else {
_cancelCache = NO;
return nil;
}
}
}

void EGOUICacheCancel() {
_cancelCache = YES;
}

void EGOUICacheSetCacheTimeoutInterval(NSTimeInterval cacheTimeoutInterval) {
_cacheTimeoutInterval = cacheTimeoutInterval;
}
Expand Down
3 changes: 3 additions & 0 deletions README.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ Created by enormego
* `EGOUICacheSetCacheTimeoutOneDay();`
* `EGOUICacheSetCacheTimeoutOneHour();`

* `EGOUICacheCancel();`
* Cancels one level of caching. This should be called if data hasn't yet loaded or something isn't what it's expected to be. The image returned by `EGOUICachedDrawing()` will be nil.

# Example

Let's say you have a button that gets drawn a bunch of times, that uses intensive blending, and really only needs to be drawn once since the text rarely changes:
Expand Down

0 comments on commit 352ab72

Please sign in to comment.