Skip to content

Commit

Permalink
1.4.0, implement rolling cache
Browse files Browse the repository at this point in the history
  • Loading branch information
Kevin Renskers committed Jan 30, 2013
1 parent 47d827d commit 60bd90f
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 2 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
1.4.0 - January 30, 2013
- New cache delegate method: - (BOOL)cacheExpiredForKey:(NSString *)key;
- To be used to implement "rolling cache"

1.3.1 - January 30, 2013
- Only call one of the cacheArray methods, not both

Expand Down
2 changes: 1 addition & 1 deletion LastFm.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = "LastFm"
s.version = "1.3.1"
s.version = "1.4.0"
s.summary = "Block based Last.fm SDK for iOS and Mac OS X."
s.homepage = "https://github.com/gangverk/LastFm"
s.license = 'MIT'
Expand Down
2 changes: 2 additions & 0 deletions LastFm/LastFm.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ typedef void (^LastFmReturnBlockWithError)(NSError *error);
@optional
- (NSArray *)cachedArrayForKey:(NSString *)key;
- (NSArray *)cachedArrayForKey:(NSString *)key requestParams:(NSDictionary *)params;
- (BOOL)cacheExpiredForKey:(NSString *)key;
- (BOOL)cacheExpiredForKey:(NSString *)key requestParams:(NSDictionary *)params;
- (void)cacheArray:(NSArray *)array forKey:(NSString *)key maxAge:(NSTimeInterval)maxAge;
- (void)cacheArray:(NSArray *)array requestParams:(NSDictionary *)params forKey:(NSString *)key maxAge:(NSTimeInterval)maxAge;
@end
Expand Down
18 changes: 17 additions & 1 deletion LastFm/LastFm.m
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,23 @@ - (NSOperation *)performApiCallForMethod:(NSString*)method
if (successHandler) {
successHandler(returnObject);
}
return nil;

if (self.cacheDelegate && [self.cacheDelegate respondsToSelector:@selector(cacheExpiredForKey:)]) {
BOOL expired = [self.cacheDelegate cacheExpiredForKey:cacheKey];
if (!expired) {
// Not expired? Then don't make the request to the server. Stop here.
return nil;
}
} if (self.cacheDelegate && [self.cacheDelegate respondsToSelector:@selector(cacheExpiredForKey:requestParams:)]) {
BOOL expired = [self.cacheDelegate cacheExpiredForKey:cacheKey requestParams:newParams];
if (!expired) {
// Not expired? Then don't make the request to the server. Stop here.
return nil;
}
} else {
// No expiration delegate methods? Stop here.
return nil;
}
}

// We need to send all the params in a sorted fashion
Expand Down

0 comments on commit 60bd90f

Please sign in to comment.