Skip to content

Commit

Permalink
cacheKey > key
Browse files Browse the repository at this point in the history
  • Loading branch information
hpique committed Sep 17, 2014
1 parent 930802c commit 29aea82
Show file tree
Hide file tree
Showing 13 changed files with 69 additions and 69 deletions.
2 changes: 1 addition & 1 deletion Haneke/HNKCache.h
Expand Up @@ -134,7 +134,7 @@
Returns the key of the original image returned by the fetcher.
@discussion If two different fetchers provide the same image, they should return the same key for better performance.
*/
@property (nonatomic, readonly) NSString *cacheKey;
@property (nonatomic, readonly) NSString *key;

/**
Retrieves the original image associated with the fetcher.
Expand Down
4 changes: 2 additions & 2 deletions Haneke/HNKCache.m
Expand Up @@ -124,7 +124,7 @@ - (NSDictionary*)formats

- (BOOL)fetchImageForFetcher:(id<HNKFetcher>)fetcher formatName:(NSString *)formatName success:(void (^)(UIImage *image))successBlock failure:(void (^)(NSError *error))failureBlock
{
NSString *key = fetcher.cacheKey;
NSString *key = fetcher.key;
return [self fetchImageForKey:key formatName:formatName success:^(UIImage *image) {
if (successBlock) successBlock(image);
} failure:^(NSError *error) {
Expand Down Expand Up @@ -259,7 +259,7 @@ - (void)fetchImageFromFetcher:(id<HNKFetcher>)fetcher completionBlock:(void(^)(U
}
else
{
NSString *key = fetcher.cacheKey;
NSString *key = fetcher.key;
NSString *errorDescription = [NSString stringWithFormat:NSLocalizedString(@"Invalid fetcher %@: Must return non-nil in success block", @""), key.lastPathComponent];
HanekeLog(@"%@", errorDescription);
NSDictionary *userInfo = @{ NSLocalizedDescriptionKey : errorDescription };
Expand Down
2 changes: 1 addition & 1 deletion Haneke/HNKDiskFetcher.m
Expand Up @@ -34,7 +34,7 @@ - (instancetype)initWithPath:(NSString*)path
return self;
}

- (NSString*)cacheKey
- (NSString*)key
{
return _path;
}
Expand Down
2 changes: 1 addition & 1 deletion Haneke/HNKNetworkFetcher.m
Expand Up @@ -35,7 +35,7 @@ - (instancetype)initWithURL:(NSURL*)URL
return self;
}

- (NSString*)cacheKey
- (NSString*)key
{
return _URL.absoluteString;
}
Expand Down
2 changes: 1 addition & 1 deletion Haneke/HNKSimpleFetcher.m
Expand Up @@ -35,7 +35,7 @@ - (instancetype)initWithKey:(NSString*)key image:(UIImage*)image
return self;
}

- (NSString*)cacheKey
- (NSString*)key
{
return _key;
}
Expand Down
12 changes: 6 additions & 6 deletions Haneke/UIButton+Haneke.m
Expand Up @@ -149,12 +149,12 @@ - (BOOL)hnk_fetchImageFromFetcher:(id<HNKFetcher>)fetcher forState:(UIControlSta
__weak __typeof__(self) weakSelf = self;
const BOOL didSetImage = [[HNKCache sharedCache] fetchImageForFetcher:fetcher formatName:format.name success:^(UIImage *image) {
__typeof__(weakSelf) strongSelf = weakSelf;
if ([strongSelf hnk_shouldCancelSetImageForKey:fetcher.cacheKey]) return;
if ([strongSelf hnk_shouldCancelSetImageForKey:fetcher.key]) return;

[strongSelf hnk_setImage:image forState:state animated:animated success:successBlock];
} failure:^(NSError *error) {
__typeof__(weakSelf) strongSelf = weakSelf;
if ([strongSelf hnk_shouldCancelSetImageForKey:fetcher.cacheKey]) return;
if ([strongSelf hnk_shouldCancelSetImageForKey:fetcher.key]) return;

strongSelf.hnk_imageFetcher = nil;

Expand Down Expand Up @@ -183,7 +183,7 @@ - (void)hnk_setImage:(UIImage*)image forState:(UIControlState)state animated:(BO

- (BOOL)hnk_shouldCancelSetImageForKey:(NSString*)key
{
if ([self.hnk_imageFetcher.cacheKey isEqualToString:key]) return NO;
if ([self.hnk_imageFetcher.key isEqualToString:key]) return NO;

HanekeLog(@"Cancelled set image from key %@", key.lastPathComponent);
return YES;
Expand Down Expand Up @@ -310,12 +310,12 @@ - (BOOL)hnk_fetchBackgroundImageFromFetcher:(id<HNKFetcher>)fetcher forState:(UI
__weak __typeof__(self) weakSelf = self;
const BOOL didSetImage = [[HNKCache sharedCache] fetchImageForFetcher:fetcher formatName:format.name success:^(UIImage *image) {
__typeof__(weakSelf) strongSelf = weakSelf;
if ([strongSelf hnk_shouldCancelSetBackgroundImageForKey:fetcher.cacheKey]) return;
if ([strongSelf hnk_shouldCancelSetBackgroundImageForKey:fetcher.key]) return;

[strongSelf hnk_setBackgroundImage:image forState:state animated:animated success:successBlock];
} failure:^(NSError *error) {
__typeof__(weakSelf) strongSelf = weakSelf;
if ([strongSelf hnk_shouldCancelSetBackgroundImageForKey:fetcher.cacheKey]) return;
if ([strongSelf hnk_shouldCancelSetBackgroundImageForKey:fetcher.key]) return;

strongSelf.hnk_backgroundImageFetcher = nil;

Expand Down Expand Up @@ -344,7 +344,7 @@ - (void)hnk_setBackgroundImage:(UIImage*)image forState:(UIControlState)state an

- (BOOL)hnk_shouldCancelSetBackgroundImageForKey:(NSString*)key
{
if ([self.hnk_backgroundImageFetcher.cacheKey isEqualToString:key]) return NO;
if ([self.hnk_backgroundImageFetcher.key isEqualToString:key]) return NO;

HanekeLog(@"Cancelled set background image from key %@", key.lastPathComponent);
return YES;
Expand Down
6 changes: 3 additions & 3 deletions Haneke/UIImageView+Haneke.m
Expand Up @@ -133,12 +133,12 @@ - (BOOL)hnk_fetchImageForFetcher:(id<HNKFetcher>)fetcher success:(void (^)(UIIma
__weak __typeof__(self) weakSelf = self;
const BOOL didSetImage = [[HNKCache sharedCache] fetchImageForFetcher:fetcher formatName:format.name success:^(UIImage *image) {
__typeof__(weakSelf) strongSelf = weakSelf;
if ([strongSelf hnk_shouldCancelForKey:fetcher.cacheKey]) return;
if ([strongSelf hnk_shouldCancelForKey:fetcher.key]) return;

[strongSelf hnk_setImage:image animated:animated success:successBlock];
} failure:^(NSError *error) {
__typeof__(weakSelf) strongSelf = weakSelf;
if ([strongSelf hnk_shouldCancelForKey:fetcher.cacheKey]) return;
if ([strongSelf hnk_shouldCancelForKey:fetcher.key]) return;

strongSelf.hnk_fetcher = nil;

Expand Down Expand Up @@ -167,7 +167,7 @@ - (void)hnk_setImage:(UIImage*)image animated:(BOOL)animated success:(void (^)(U

- (BOOL)hnk_shouldCancelForKey:(NSString*)key
{
if ([self.hnk_fetcher.cacheKey isEqualToString:key]) return NO;
if ([self.hnk_fetcher.key isEqualToString:key]) return NO;

HanekeLog(@"Cancelled set image for %@", key.lastPathComponent);
return YES;
Expand Down
2 changes: 1 addition & 1 deletion HanekeTests/HNKCacheTests.m
Expand Up @@ -210,7 +210,7 @@ - (void)testFetchImageForFetcher_MemoryCacheHit
id<HNKFetcher> fetcher = [HNKCache fetcherWithKey:@"1" image:image];
HNKCacheFormat *format = [_sut registerFormatWithSize:CGSizeMake(1, 1)];
NSString *formatName = format.name;
[_sut setImage:image forKey:fetcher.cacheKey formatName:formatName];
[_sut setImage:image forKey:fetcher.key formatName:formatName];

BOOL result = [_sut fetchImageForFetcher:fetcher formatName:format.name success:^(UIImage *result) {
XCTAssertEqualObjects(result, image, @"");
Expand Down
4 changes: 2 additions & 2 deletions HanekeTests/HNKDiskFetcherTests.m
Expand Up @@ -49,12 +49,12 @@ - (void)tearDown
[super tearDown];
}

- (void)testCacheKey
- (void)testKey
{
NSString *path = [_directory stringByAppendingPathComponent:self.name];
_sut = [[HNKDiskFetcher alloc] initWithPath:path];

XCTAssertEqualObjects(_sut.cacheKey, path, @"");
XCTAssertEqualObjects(_sut.key, path, @"");
}

- (void)testFetchImage_Success
Expand Down
4 changes: 2 additions & 2 deletions HanekeTests/HNKNetworkFetcherTests.m
Expand Up @@ -51,11 +51,11 @@ - (void)testURL
XCTAssertEqualObjects(_sut.URL, _URL, @"");
}

- (void)testCacheKey
- (void)testKey
{
_sut = [[HNKNetworkFetcher alloc] initWithURL:_URL];

XCTAssertEqualObjects(_sut.cacheKey, _URL.absoluteString, @"");
XCTAssertEqualObjects(_sut.key, _URL.absoluteString, @"");
}

- (void)testFetchImage_Success
Expand Down
4 changes: 2 additions & 2 deletions HanekeTests/HNKSimpleFetcherTests.m
Expand Up @@ -30,13 +30,13 @@ @implementation HNKSimpleFetcherTests {
HNKSimpleFetcher *_sut;
}

- (void)testCacheKey
- (void)testKey
{
UIImage *image = [UIImage hnk_imageWithColor:[UIColor greenColor] size:CGSizeMake(10, 10)];
NSString *key = self.name;
_sut = [[HNKSimpleFetcher alloc] initWithKey:key image:image];

XCTAssertEqualObjects(_sut.cacheKey, key, @"");
XCTAssertEqualObjects(_sut.key, key, @"");
}

- (void)testFetchImage
Expand Down

0 comments on commit 29aea82

Please sign in to comment.