diff --git a/Source/PINCache.m b/Source/PINCache.m index b468fd3e..0bfdf8b1 100644 --- a/Source/PINCache.m +++ b/Source/PINCache.m @@ -73,7 +73,7 @@ - (instancetype)initWithName:(NSString *)name keyDecoder:keyDecoder operationQueue:_operationQueue ttlCache:ttlCache]; - _memoryCache = [[PINMemoryCache alloc] initWithName:_name operationQueue:_operationQueue]; + _memoryCache = [[PINMemoryCache alloc] initWithName:_name operationQueue:_operationQueue ttlCache:ttlCache]; } return self; } diff --git a/Tests/PINCacheTests.m b/Tests/PINCacheTests.m index a96d3ddc..4d89f9ad 100644 --- a/Tests/PINCacheTests.m +++ b/Tests/PINCacheTests.m @@ -115,14 +115,8 @@ - (void)testCoreProperties - (void)testDiskCacheURL { - // Wait for URL to be created - dispatch_group_t group = dispatch_group_create(); - dispatch_group_enter(group); - [self.cache objectForKeyAsync:@"" completion:^(PINCache * _Nonnull cache, NSString * _Nonnull key, id _Nullable object) { - dispatch_group_leave(group); - }]; - - dispatch_group_wait(group, DISPATCH_TIME_FOREVER); + // Wait for URL to be created. We use enumerateObjectsWithBlock because it waits for a known disk state. + [self.cache.diskCache enumerateObjectsWithBlock:^(NSString * _Nonnull key, NSURL * _Nullable fileURL, BOOL * _Nonnull stop) {}]; BOOL isDir = NO; BOOL exists = [[NSFileManager defaultManager] fileExistsAtPath:[self.cache.diskCache.cacheURL path] isDirectory:&isDir]; @@ -1376,4 +1370,10 @@ - (void)testCustomEncoderDecoder { } +- (void)testTTLCacheIsSet { + PINCache *cache = [[PINCache alloc] initWithName:@"test" rootPath:PINDiskCachePrefix serializer:nil deserializer:nil keyEncoder:nil keyDecoder:nil ttlCache:YES]; + XCTAssert(cache.diskCache.isTTLCache); + XCTAssert(cache.memoryCache.isTTLCache); +} + @end