Skip to content

Commit

Permalink
Cleanup and clarification
Browse files Browse the repository at this point in the history
Correct selector

[NSDate stopMockingDate];

Update .podspec
  • Loading branch information
wiseoldduck committed Jun 8, 2018
1 parent f047d3c commit 4534575
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
2 changes: 1 addition & 1 deletion PINRemoteImage.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ Pod::Spec.new do |s|

s.subspec "PINCache" do |pc|
pc.dependency 'PINRemoteImage/Core'
pc.dependency 'PINCache', '=3.0.1-beta.6'
pc.dependency 'PINCache', '=3.0.1-beta.7'
pc.ios.deployment_target = ios_deployment
pc.tvos.deployment_target = tvos_deployment
pc.osx.deployment_target = osx_deployment
Expand Down
10 changes: 6 additions & 4 deletions Source/Classes/PINRemoteImageManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -168,12 +168,12 @@ - (nonnull instancetype)initWithSessionConfiguration:(nullable NSURLSessionConfi
{
if (self = [super init]) {
if (imageCache) {
self.isTtlCache = [imageCache respondsToSelector:@selector(setObjectforKey:withAgeLimit:)];
self.cache = imageCache;
} else {
self.cache = [self defaultImageCache];
}

self.isTtlCache = [self.cache respondsToSelector:@selector(setObjectOnDisk:forKey:withAgeLimit:)];

_sessionConfiguration = [configuration copy];
if (!_sessionConfiguration) {
_sessionConfiguration = [NSURLSessionConfiguration ephemeralSessionConfiguration];
Expand Down Expand Up @@ -240,14 +240,13 @@ - (nonnull instancetype)initWithSessionConfiguration:(nullable NSURLSessionConfi
[pinDefaults setInteger:kPINRemoteImageDiskCacheVersion forKey:kPINRemoteImageDiskCacheVersionKey];
}

self.isTtlCache = YES;
return [[PINCache alloc] initWithName:kPINRemoteImageDiskCacheName rootPath:cacheURLRoot serializer:^NSData * (id <NSCoding> _Nonnull object, NSString * _Nonnull key) {
id <NSCoding, NSObject> obj = (id <NSCoding, NSObject>)object;
if ([key hasPrefix:PINRemoteImageCacheKeyResumePrefix]) {
return [NSKeyedArchiver archivedDataWithRootObject:obj];
}
return (NSData *)object;
} deserializer:^id <NSCoding> _Nonnull(NSData *_Nonnull data, NSString *_Nonnull key) {
} deserializer:^id <NSCoding> _Nonnull(NSData * _Nonnull data, NSString * _Nonnull key) {
if ([key hasPrefix:PINRemoteImageCacheKeyResumePrefix]) {
return [NSKeyedUnarchiver unarchiveObjectWithData:data];
}
Expand Down Expand Up @@ -832,6 +831,8 @@ - (void)downloadImageWithURL:(NSURL *)url
}

date = [sRFC7231PreferredDateFormatter dateFromString:expires];

// Invalid dates (notably "0") or dates in the past must not be cached (RFC7231 5.3)
maxAge = @((NSInteger) MAX(([date timeIntervalSinceNow]), 0));
}
}
Expand Down Expand Up @@ -1423,6 +1424,7 @@ - (BOOL)materializeAndCacheObject:(id)object
if (maxAge && _isTtlCache) {
[self.cache setObjectOnDisk:diskData forKey:key withAgeLimit:[maxAge integerValue]];
} else {
// unset (nil) maxAge, or a cache that is not _isTtlCache behave as before (will use cache global ageLimit)
[self.cache setObjectOnDisk:diskData forKey:key];
}
}
Expand Down
2 changes: 1 addition & 1 deletion Tests/PINRemoteImageTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -968,7 +968,6 @@ - (void)testMaxAge

diskCachedObj = [cache objectFromDiskForKey:key];
XCTAssert(diskCachedObj == nil, @"Image was not discarded from the disk cache");

[NSDate stopMockingDate];

// nonTransparentWebPURL includes the header "expires: <about 1 yr from now>"
Expand All @@ -987,6 +986,7 @@ - (void)testMaxAge

diskCachedObj = [cache objectFromDiskForKey:key];
XCTAssert(diskCachedObj == nil, @"Image #2 was not discarded from the disk cache");
[NSDate stopMockingDate];
}

- (void)testAuthentication
Expand Down

0 comments on commit 4534575

Please sign in to comment.