@@ -130,7 +130,7 @@ - (void)testObjectSet
130
130
__block PINImage *image = nil ;
131
131
dispatch_semaphore_t semaphore = dispatch_semaphore_create (0 );
132
132
133
- [self .cache setObjectAsync: [self image ] forKey: key completion: ^(PINCache * cache, NSString *key, id object) {
133
+ [self .cache setObjectAsync: [self image ] forKey: key completion: ^(id <PINCaching> cache, NSString *key, id object) {
134
134
image = (PINImage *)object;
135
135
dispatch_semaphore_signal (semaphore);
136
136
}];
@@ -148,7 +148,7 @@ - (void)testObjectSetWithCost
148
148
PINImage *srcImage = [self image ];
149
149
NSUInteger cost = (NSUInteger )(srcImage.size .width * srcImage.size .height );
150
150
151
- [self .cache setObjectAsync: srcImage forKey: key withCost: cost completion: ^(PINCache * cache, NSString *key, id object) {
151
+ [self .cache setObjectAsync: srcImage forKey: key withCost: cost completion: ^(id <PINCaching> cache, NSString *key, id object) {
152
152
image = (PINImage *)object;
153
153
dispatch_semaphore_signal (semaphore);
154
154
}];
@@ -170,7 +170,7 @@ - (void)testObjectSetWithDuplicateKey
170
170
[self .cache setObject: value1 forKey: key];
171
171
[self .cache setObject: value2 forKey: key];
172
172
173
- [self .cache objectForKeyAsync: key completion: ^(PINCache * cache, NSString *key, id object) {
173
+ [self .cache objectForKeyAsync: key completion: ^(id <PINCaching> cache, NSString *key, id object) {
174
174
cachedValue = (NSString *)object;
175
175
dispatch_semaphore_signal (semaphore);
176
176
}];
@@ -233,7 +233,7 @@ - (void)testObjectGet
233
233
234
234
self.cache [key] = [self image ];
235
235
236
- [self .cache objectForKeyAsync: key completion: ^(PINCache * cache, NSString *key, id object) {
236
+ [self .cache objectForKeyAsync: key completion: ^(id <PINCaching> cache, NSString *key, id object) {
237
237
image = (PINImage *)object;
238
238
dispatch_semaphore_signal (semaphore);
239
239
}];
@@ -252,7 +252,7 @@ - (void)testObjectGetWithInvalidKey
252
252
253
253
self.cache [key] = [self image ];
254
254
255
- [self .cache objectForKeyAsync: invalidKey completion: ^(PINCache * cache, NSString *key, id object) {
255
+ [self .cache objectForKeyAsync: invalidKey completion: ^(id <PINCaching> cache, NSString *key, id object) {
256
256
image = (PINImage *)object;
257
257
dispatch_semaphore_signal (semaphore);
258
258
}];
@@ -279,7 +279,7 @@ - (void)testObjectRemove
279
279
didRemoveObjectBlockCalled = YES ;
280
280
};
281
281
282
- [self .cache removeObjectForKeyAsync: key completion: ^(PINCache * cache, NSString *key, id object) {
282
+ [self .cache removeObjectForKeyAsync: key completion: ^(id <PINCaching> cache, NSString *key, id object) {
283
283
dispatch_semaphore_signal (semaphore);
284
284
}];
285
285
@@ -311,7 +311,7 @@ - (void)testObjectRemoveAll
311
311
didRemoveAllObjectsBlockCalled = YES ;
312
312
};
313
313
314
- [self .cache removeAllObjectsAsync: ^(PINCache * cache) {
314
+ [self .cache removeAllObjectsAsync: ^(id <PINCaching> cache) {
315
315
dispatch_semaphore_signal (semaphore);
316
316
}];
317
317
@@ -505,9 +505,9 @@ - (void)testOneThousandAndOneWrites
505
505
#pragma clang diagnostic push
506
506
#pragma clang diagnostic ignored "-Warc-retain-cycles"
507
507
dispatch_group_enter (group);
508
- [self .cache setObjectAsync: obj forKey: key completion: ^(PINCache * _Nonnull cache, NSString * _Nonnull key, id _Nullable object) {
508
+ [self .cache setObjectAsync: obj forKey: key completion: ^(id <PINCaching> _Nonnull cache, NSString * _Nonnull key, id _Nullable object) {
509
509
dispatch_async (queue, ^{
510
- [self .cache objectForKeyAsync: key completion: ^(PINCache * _Nonnull cache, NSString * _Nonnull key, id _Nullable object) {
510
+ [self .cache objectForKeyAsync: key completion: ^(id <PINCaching> _Nonnull cache, NSString * _Nonnull key, id _Nullable object) {
511
511
NSString *obj = [[NSString alloc ] initWithFormat: @" obj %lu " , (unsigned long )i];
512
512
XCTAssertTrue ([object isEqualToString: obj] == YES , @" object returned was not object set" );
513
513
@synchronized (self) {
@@ -535,7 +535,7 @@ - (void)testMemoryWarningBlock
535
535
536
536
__block BOOL blockDidExecute = NO ;
537
537
538
- self.cache .memoryCache .didReceiveMemoryWarningBlock = ^(PINMemoryCache * cache) {
538
+ self.cache .memoryCache .didReceiveMemoryWarningBlock = ^(id <PINCaching> cache) {
539
539
blockDidExecute = YES ;
540
540
dispatch_semaphore_signal (semaphore);
541
541
};
@@ -554,7 +554,7 @@ - (void)testBackgroundBlock
554
554
555
555
__block BOOL blockDidExecute = NO ;
556
556
557
- self.cache .memoryCache .didEnterBackgroundBlock = ^(PINMemoryCache * cache) {
557
+ self.cache .memoryCache .didEnterBackgroundBlock = ^(id <PINCaching> cache) {
558
558
blockDidExecute = YES ;
559
559
dispatch_semaphore_signal (semaphore);
560
560
};
@@ -591,8 +591,8 @@ - (void)testMemoryWarningProperty
591
591
592
592
__block id object = nil ;
593
593
594
- self.cache .memoryCache .didReceiveMemoryWarningBlock = ^(PINMemoryCache * cache) {
595
- object = cache[ @" object" ];
594
+ self.cache .memoryCache .didReceiveMemoryWarningBlock = ^(id <PINCaching> cache) {
595
+ object = [cache objectForKey: @" object" ];
596
596
dispatch_semaphore_signal (semaphore);
597
597
};
598
598
@@ -620,12 +620,13 @@ - (void)testMemoryCacheEnumerationWithWarning
620
620
621
621
__block NSUInteger enumCount = 0 ;
622
622
623
- self.cache .memoryCache .didReceiveMemoryWarningBlock = ^(PINMemoryCache *cache) {
624
- [cache enumerateObjectsWithBlockAsync: ^(PINMemoryCache *cache, NSString *key, id object, BOOL *stop) {
623
+ self.cache .memoryCache .didReceiveMemoryWarningBlock = ^(id <PINCaching> cache) {
624
+ PINMemoryCache *memoryCache = (PINMemoryCache *)cache;
625
+ [memoryCache enumerateObjectsWithBlockAsync: ^(id <PINCaching> cache, NSString *key, id object, BOOL *stop) {
625
626
@synchronized (self) {
626
627
enumCount++;
627
628
}
628
- } completionBlock: ^(PINMemoryCache * cache) {
629
+ } completionBlock: ^(id <PINCaching> cache) {
629
630
dispatch_semaphore_signal (semaphore);
630
631
}];
631
632
};
@@ -665,7 +666,7 @@ - (void)testDiskCacheEnumeration
665
666
@synchronized (self) {
666
667
enumCount++;
667
668
}
668
- } completionBlock: ^(PINDiskCache * cache) {
669
+ } completionBlock: ^(id <PINCaching> cache) {
669
670
dispatch_semaphore_signal (semaphore);
670
671
}];
671
672
@@ -722,25 +723,25 @@ - (void)testAgeLimit
722
723
__block id diskObj2 = nil ;
723
724
724
725
dispatch_group_enter (group);
725
- [self .cache.memoryCache objectForKeyAsync: key1 completion: ^(PINMemoryCache * cache, NSString *key, id object) {
726
+ [self .cache.memoryCache objectForKeyAsync: key1 completion: ^(id <PINCaching> cache, NSString *key, id object) {
726
727
memObj1 = object;
727
728
dispatch_group_leave (group);
728
729
}];
729
730
730
731
dispatch_group_enter (group);
731
- [self .cache.memoryCache objectForKeyAsync: key2 completion: ^(PINMemoryCache * cache, NSString *key, id object) {
732
+ [self .cache.memoryCache objectForKeyAsync: key2 completion: ^(id <PINCaching> cache, NSString *key, id object) {
732
733
memObj2 = object;
733
734
dispatch_group_leave (group);
734
735
}];
735
736
736
737
dispatch_group_enter (group);
737
- [self .cache.diskCache objectForKeyAsync: key1 completion: ^(PINDiskCache * cache, NSString *key, id <NSCoding > object) {
738
+ [self .cache.diskCache objectForKeyAsync: key1 completion: ^(id <PINCaching> cache, NSString *key, id <NSCoding > object) {
738
739
diskObj1 = object;
739
740
dispatch_group_leave (group);
740
741
}];
741
742
742
743
dispatch_group_enter (group);
743
- [self .cache.diskCache objectForKeyAsync: key2 completion: ^(PINDiskCache * cache, NSString *key, id <NSCoding > object) {
744
+ [self .cache.diskCache objectForKeyAsync: key2 completion: ^(id <PINCaching> cache, NSString *key, id <NSCoding > object) {
744
745
diskObj2 = object;
745
746
dispatch_group_leave (group);
746
747
}];
@@ -765,19 +766,19 @@ - (void)testAgeLimit
765
766
sleep (1 );
766
767
767
768
dispatch_group_enter (group);
768
- [self .cache.memoryCache objectForKeyAsync: key1 completion: ^(PINMemoryCache * cache, NSString *key, id object) {
769
+ [self .cache.memoryCache objectForKeyAsync: key1 completion: ^(id <PINCaching> cache, NSString *key, id object) {
769
770
memObj1 = object;
770
771
dispatch_group_leave (group);
771
772
}];
772
773
773
774
dispatch_group_enter (group);
774
- [self .cache.memoryCache objectForKeyAsync: key2 completion: ^(PINMemoryCache * cache, NSString *key, id object) {
775
+ [self .cache.memoryCache objectForKeyAsync: key2 completion: ^(id <PINCaching> cache, NSString *key, id object) {
775
776
memObj2 = object;
776
777
dispatch_group_leave (group);
777
778
}];
778
779
779
780
dispatch_group_enter (group);
780
- [self .cache.diskCache objectForKeyAsync: key1 completion: ^(PINDiskCache * cache, NSString *key, id <NSCoding > object) {
781
+ [self .cache.diskCache objectForKeyAsync: key1 completion: ^(id <PINCaching> cache, NSString *key, id <NSCoding > object) {
781
782
diskObj1 = object;
782
783
dispatch_group_leave (group);
783
784
}];
@@ -902,13 +903,13 @@ - (void)_testTTLCacheObjectAccess {
902
903
__block id diskObj = nil ;
903
904
904
905
dispatch_group_enter (group);
905
- [self .cache.memoryCache objectForKeyAsync: key completion: ^(PINMemoryCache * cache, NSString *key, id object) {
906
+ [self .cache.memoryCache objectForKeyAsync: key completion: ^(id <PINCaching> cache, NSString *key, id object) {
906
907
memObj = object;
907
908
dispatch_group_leave (group);
908
909
}];
909
910
910
911
dispatch_group_enter (group);
911
- [self .cache.diskCache objectForKeyAsync: key completion: ^(PINDiskCache * cache, NSString *key, id <NSCoding > object) {
912
+ [self .cache.diskCache objectForKeyAsync: key completion: ^(id <PINCaching> cache, NSString *key, id <NSCoding > object) {
912
913
diskObj = object;
913
914
dispatch_group_leave (group);
914
915
}];
@@ -926,13 +927,13 @@ - (void)_testTTLCacheObjectAccess {
926
927
diskObj = nil ;
927
928
928
929
dispatch_group_enter (group);
929
- [self .cache.memoryCache objectForKeyAsync: key completion: ^(PINMemoryCache * cache, NSString *key, id object) {
930
+ [self .cache.memoryCache objectForKeyAsync: key completion: ^(id <PINCaching> cache, NSString *key, id object) {
930
931
memObj = object;
931
932
dispatch_group_leave (group);
932
933
}];
933
934
934
935
dispatch_group_enter (group);
935
- [self .cache.diskCache objectForKeyAsync: key completion: ^(PINDiskCache * cache, NSString *key, id <NSCoding > object) {
936
+ [self .cache.diskCache objectForKeyAsync: key completion: ^(id <PINCaching> cache, NSString *key, id <NSCoding > object) {
936
937
diskObj = object;
937
938
dispatch_group_leave (group);
938
939
}];
@@ -979,7 +980,7 @@ - (void)_testTTLCacheObjectEnumeration {
979
980
XCTAssertEqual (objCount, expectedObjCount, @" Expected %lu objects in the cache" , (unsigned long )expectedObjCount);
980
981
981
982
objCount = 0 ;
982
- [self .cache.memoryCache enumerateObjectsWithBlock: ^(PINMemoryCache * cache, NSString *key, id _Nullable object, BOOL *stop) {
983
+ [self .cache.memoryCache enumerateObjectsWithBlock: ^(id <PINCaching> cache, NSString *key, id _Nullable object, BOOL *stop) {
983
984
objCount++;
984
985
}];
985
986
@@ -1005,7 +1006,7 @@ - (void)_testTTLCacheObjectEnumeration {
1005
1006
XCTAssertEqual (objCount, expectedObjCount, @" Expected %lu objects in the cache" , (unsigned long )expectedObjCount);
1006
1007
1007
1008
objCount = 0 ;
1008
- [self .cache.memoryCache enumerateObjectsWithBlock: ^(PINMemoryCache * _Nonnull cache, NSString * _Nonnull key, id _Nullable object, BOOL *stop) {
1009
+ [self .cache.memoryCache enumerateObjectsWithBlock: ^(id <PINCaching> _Nonnull cache, NSString * _Nonnull key, id _Nullable object, BOOL *stop) {
1009
1010
objCount++;
1010
1011
}];
1011
1012
@@ -1089,13 +1090,13 @@ - (void)testObjectTTLObjectAccess
1089
1090
// Neither object should be expired at this point and should exist in both caches
1090
1091
1091
1092
XCTestExpectation *memObjectForKey1Expectation = [self expectationWithDescription: @" memoryCache objectForKeyAsync - #1" ];
1092
- [self .cache.memoryCache objectForKeyAsync: key1 completion: ^(PINMemoryCache * cache, NSString *key, id object) {
1093
+ [self .cache.memoryCache objectForKeyAsync: key1 completion: ^(id <PINCaching> cache, NSString *key, id object) {
1093
1094
XCTAssertNotNil (object, @" should still be in memory cache" );
1094
1095
[memObjectForKey1Expectation fulfill ];
1095
1096
}];
1096
1097
1097
1098
XCTestExpectation *memObjectForKey2Expectation = [self expectationWithDescription: @" memoryCache objectForKeyAsync - #2" ];
1098
- [self .cache.memoryCache objectForKeyAsync: key2 completion: ^(PINMemoryCache * cache, NSString *key, id object) {
1099
+ [self .cache.memoryCache objectForKeyAsync: key2 completion: ^(id <PINCaching> cache, NSString *key, id object) {
1099
1100
XCTAssertNotNil (object, @" should still be in memory cache" );
1100
1101
[memObjectForKey2Expectation fulfill ];
1101
1102
}];
@@ -1120,13 +1121,13 @@ - (void)testObjectTTLObjectAccess
1120
1121
// The first object has been expired for 30 seconds and should not exist in the cache anymore.
1121
1122
1122
1123
memObjectForKey1Expectation = [self expectationWithDescription: @" memoryCache objectForKeyAsync - #1" ];
1123
- [self .cache.memoryCache objectForKeyAsync: key1 completion: ^(PINMemoryCache * cache, NSString *key, id object) {
1124
+ [self .cache.memoryCache objectForKeyAsync: key1 completion: ^(id <PINCaching> cache, NSString *key, id object) {
1124
1125
XCTAssertNil (object, @" should not be in memory cache" );
1125
1126
[memObjectForKey1Expectation fulfill ];
1126
1127
}];
1127
1128
1128
1129
memObjectForKey2Expectation = [self expectationWithDescription: @" memoryCache objectForKeyAsync - #2" ];
1129
- [self .cache.memoryCache objectForKeyAsync: key2 completion: ^(PINMemoryCache * cache, NSString *key, id object) {
1130
+ [self .cache.memoryCache objectForKeyAsync: key2 completion: ^(id <PINCaching> cache, NSString *key, id object) {
1130
1131
XCTAssertNotNil (object, @" should not be in memory cache" );
1131
1132
[memObjectForKey2Expectation fulfill ];
1132
1133
}];
@@ -1162,7 +1163,7 @@ - (void)testObjectTTLObjectEnumeration
1162
1163
// Neither object should be expired at this point and should exist in both caches
1163
1164
1164
1165
__block NSUInteger objCount = 0 ;
1165
- [self .cache.memoryCache enumerateObjectsWithBlock: ^(PINMemoryCache * cache, NSString *key, id _Nullable object, BOOL *stop) {
1166
+ [self .cache.memoryCache enumerateObjectsWithBlock: ^(id <PINCaching> cache, NSString *key, id _Nullable object, BOOL *stop) {
1166
1167
objCount++;
1167
1168
}];
1168
1169
XCTAssertEqual (objCount, 2 , @" Expected 2 objects, got %tu ." , objCount);
@@ -1179,7 +1180,7 @@ - (void)testObjectTTLObjectEnumeration
1179
1180
// The first object has been expired for 30 seconds and should not exist in the cache anymore.
1180
1181
1181
1182
objCount = 0 ;
1182
- [self .cache.memoryCache enumerateObjectsWithBlock: ^(PINMemoryCache * cache, NSString *key, id _Nullable object, BOOL *stop) {
1183
+ [self .cache.memoryCache enumerateObjectsWithBlock: ^(id <PINCaching> cache, NSString *key, id _Nullable object, BOOL *stop) {
1183
1184
objCount++;
1184
1185
}];
1185
1186
XCTAssertEqual (objCount, 1 , @" Expected 1 object, got %tu ." , objCount);
@@ -1215,13 +1216,13 @@ - (void)testRemoveExpiredObjects
1215
1216
[NSDate stopMockingDate ];
1216
1217
1217
1218
XCTestExpectation *memObjectForKey1Expectation = [self expectationWithDescription: @" memoryCache objectForKeyAsync - #1" ];
1218
- [self .cache.memoryCache objectForKeyAsync: key1 completion: ^(PINMemoryCache * cache, NSString *key, id object) {
1219
+ [self .cache.memoryCache objectForKeyAsync: key1 completion: ^(id <PINCaching> cache, NSString *key, id object) {
1219
1220
XCTAssertNil (object, @" should not be in memory cache" );
1220
1221
[memObjectForKey1Expectation fulfill ];
1221
1222
}];
1222
1223
1223
1224
XCTestExpectation *memObjectForKey2Expectation = [self expectationWithDescription: @" memoryCache objectForKeyAsync - #2" ];
1224
- [self .cache.memoryCache objectForKeyAsync: key2 completion: ^(PINMemoryCache * cache, NSString *key, id object) {
1225
+ [self .cache.memoryCache objectForKeyAsync: key2 completion: ^(id <PINCaching> cache, NSString *key, id object) {
1225
1226
XCTAssertNotNil (object, @" should not be in memory cache" );
1226
1227
[memObjectForKey2Expectation fulfill ];
1227
1228
}];
@@ -1347,7 +1348,7 @@ - (void)testDiskCacheEmptyTrash
1347
1348
}
1348
1349
1349
1350
dispatch_group_enter (group);
1350
- [self .cache.diskCache removeAllObjectsAsync: ^(PINDiskCache * _Nonnull cache) {
1351
+ [self .cache.diskCache removeAllObjectsAsync: ^(id <PINCaching> _Nonnull cache) {
1351
1352
// Temporary directory should be bigger now since the trash directory is still inside it
1352
1353
NSError *error = nil ;
1353
1354
unsigned long long tempDirSize = [[fileManager attributesOfItemAtPath: trashPath error: &error] fileSize ];
0 commit comments