| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409 |
- // PINCache is a modified version of TMCache
- // Modifications by Garrett Moon
- // Copyright (c) 2015 Pinterest. All rights reserved.
- #import "PINDiskCache.h"
- #if __IPHONE_OS_VERSION_MIN_REQUIRED >= __IPHONE_4_0
- #import <UIKit/UIKit.h>
- #endif
- #import <pthread.h>
- #import <PINOperation/PINOperation.h>
- #define PINDiskCacheError(error) if (error) { NSLog(@"%@ (%d) ERROR: %@", \
- [[NSString stringWithUTF8String:__FILE__] lastPathComponent], \
- __LINE__, [error localizedDescription]); }
- NSString * const PINDiskCachePrefix = @"com.pinterest.PINDiskCache";
- static NSString * const PINDiskCacheSharedName = @"PINDiskCacheShared";
- static NSString * const PINDiskCacheOperationIdentifierTrimToDate = @"PINDiskCacheOperationIdentifierTrimToDate";
- static NSString * const PINDiskCacheOperationIdentifierTrimToSize = @"PINDiskCacheOperationIdentifierTrimToSize";
- static NSString * const PINDiskCacheOperationIdentifierTrimToSizeByDate = @"PINDiskCacheOperationIdentifierTrimToSizeByDate";
- typedef NS_ENUM(NSUInteger, PINDiskCacheCondition) {
- PINDiskCacheConditionNotReady = 0,
- PINDiskCacheConditionReady = 1,
- };
- static PINOperationDataCoalescingBlock PINDiskTrimmingSizeCoalescingBlock = ^id(NSNumber *existingSize, NSNumber *newSize) {
- NSComparisonResult result = [existingSize compare:newSize];
- return (result == NSOrderedDescending) ? newSize : existingSize;
- };
- static PINOperationDataCoalescingBlock PINDiskTrimmingDateCoalescingBlock = ^id(NSDate *existingDate, NSDate *newDate) {
- NSComparisonResult result = [existingDate compare:newDate];
- return (result == NSOrderedDescending) ? newDate : existingDate;
- };
- @interface PINDiskCache () {
- NSConditionLock *_instanceLock;
-
- PINDiskCacheSerializerBlock _serializer;
- PINDiskCacheDeserializerBlock _deserializer;
- }
- @property (copy, nonatomic) NSString *name;
- @property (assign) NSUInteger byteCount;
- @property (strong, nonatomic) NSURL *cacheURL;
- @property (strong, nonatomic) PINOperationQueue *operationQueue;
- @property (strong, nonatomic) NSMutableDictionary *dates;
- @property (strong, nonatomic) NSMutableDictionary *sizes;
- @end
- @implementation PINDiskCache
- static NSURL *_sharedTrashURL;
- @synthesize willAddObjectBlock = _willAddObjectBlock;
- @synthesize willRemoveObjectBlock = _willRemoveObjectBlock;
- @synthesize willRemoveAllObjectsBlock = _willRemoveAllObjectsBlock;
- @synthesize didAddObjectBlock = _didAddObjectBlock;
- @synthesize didRemoveObjectBlock = _didRemoveObjectBlock;
- @synthesize didRemoveAllObjectsBlock = _didRemoveAllObjectsBlock;
- @synthesize byteLimit = _byteLimit;
- @synthesize ageLimit = _ageLimit;
- @synthesize ttlCache = _ttlCache;
- #if TARGET_OS_IPHONE
- @synthesize writingProtectionOption = _writingProtectionOption;
- #endif
- #pragma mark - Initialization -
- - (instancetype)init
- {
- @throw [NSException exceptionWithName:@"Must initialize with a name" reason:@"PINDiskCache must be initialized with a name. Call initWithName: instead." userInfo:nil];
- return [self initWithName:@""];
- }
- - (instancetype)initWithName:(NSString *)name
- {
- return [self initWithName:name fileExtension:nil];
- }
- - (instancetype)initWithName:(NSString *)name fileExtension:(NSString *)fileExtension
- {
- return [self initWithName:name rootPath:[NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) objectAtIndex:0] fileExtension:fileExtension];
- }
- - (instancetype)initWithName:(NSString *)name rootPath:(NSString *)rootPath fileExtension:(NSString *)fileExtension
- {
- return [self initWithName:name rootPath:rootPath serializer:nil deserializer:nil fileExtension:fileExtension];
- }
- - (instancetype)initWithName:(NSString *)name rootPath:(NSString *)rootPath serializer:(PINDiskCacheSerializerBlock)serializer deserializer:(PINDiskCacheDeserializerBlock)deserializer fileExtension:(NSString *)fileExtension
- {
- #pragma clang diagnostic push
- #pragma clang diagnostic ignored "-Wdeprecated-declarations"
- return [self initWithName:name rootPath:rootPath serializer:serializer deserializer:deserializer fileExtension:fileExtension operationQueue:[PINOperationQueue sharedOperationQueue]];
- #pragma clang diagnostic pop
- }
- - (instancetype)initWithName:(NSString *)name
- rootPath:(NSString *)rootPath
- serializer:(PINDiskCacheSerializerBlock)serializer
- deserializer:(PINDiskCacheDeserializerBlock)deserializer
- fileExtension:(NSString *)fileExtension
- operationQueue:(PINOperationQueue *)operationQueue
- {
- return [self initWithName:name prefix:PINDiskCachePrefix rootPath:rootPath serializer:serializer deserializer:deserializer fileExtension:fileExtension operationQueue:operationQueue];
- }
- - (instancetype)initWithName:(NSString *)name
- prefix:(NSString *)prefix
- rootPath:(NSString *)rootPath
- serializer:(PINDiskCacheSerializerBlock)serializer
- deserializer:(PINDiskCacheDeserializerBlock)deserializer
- fileExtension:(NSString *)fileExtension
- operationQueue:(PINOperationQueue *)operationQueue
- {
- if (!name)
- return nil;
-
- if ((serializer && !deserializer) ||
- (!serializer && deserializer)){
- @throw [NSException exceptionWithName:@"Must initialize with a both serializer and deserializer" reason:@"PINDiskCache must be initialized with a serializer and deserializer." userInfo:nil];
- return nil;
- }
-
- if (self = [super init]) {
- _name = [name copy];
- _prefix = [prefix copy];
- _fileExtension = [fileExtension copy];
- _operationQueue = operationQueue;
- _instanceLock = [[NSConditionLock alloc] initWithCondition:PINDiskCacheConditionNotReady];
- _willAddObjectBlock = nil;
- _willRemoveObjectBlock = nil;
- _willRemoveAllObjectsBlock = nil;
- _didAddObjectBlock = nil;
- _didRemoveObjectBlock = nil;
- _didRemoveAllObjectsBlock = nil;
-
- _byteCount = 0;
- _byteLimit = 0;
- _ageLimit = 0.0;
-
- #if TARGET_OS_IPHONE
- _writingProtectionOption = NSDataWritingFileProtectionNone;
- #endif
-
- _dates = [[NSMutableDictionary alloc] init];
- _sizes = [[NSMutableDictionary alloc] init];
-
- _cacheURL = [[self class] cacheURLWithRootPath:rootPath prefix:_prefix name:_name];
-
- //setup serializers
- if(serializer) {
- _serializer = [serializer copy];
- } else {
- _serializer = self.defaultSerializer;
- }
- if(deserializer) {
- _deserializer = [deserializer copy];
- } else {
- _deserializer = self.defaultDeserializer;
- }
- //we don't want to do anything without setting up the disk cache, but we also don't want to block init, it can take a while to initialize. This must *not* be done on _operationQueue because other operations added may hold the lock and fill up the queue.
- dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
- //should always be able to aquire the lock unless the below code is running.
- [_instanceLock lockWhenCondition:PINDiskCacheConditionNotReady];
- [self _locked_createCacheDirectory];
- [self _locked_initializeDiskProperties];
- [_instanceLock unlockWithCondition:PINDiskCacheConditionReady];
- });
- }
- return self;
- }
- - (NSString *)description
- {
- return [[NSString alloc] initWithFormat:@"%@.%@.%p", PINDiskCachePrefix, _name, (void *)self];
- }
- + (PINDiskCache *)sharedCache
- {
- static PINDiskCache *cache;
- static dispatch_once_t predicate;
-
- dispatch_once(&predicate, ^{
- cache = [[PINDiskCache alloc] initWithName:PINDiskCacheSharedName];
- });
-
- return cache;
- }
- + (NSURL *)cacheURLWithRootPath:(NSString *)rootPath prefix:(NSString *)prefix name:(NSString *)name
- {
- NSString *pathComponent = [[NSString alloc] initWithFormat:@"%@.%@", prefix, name];
- return [NSURL fileURLWithPathComponents:@[ rootPath, pathComponent ]];
- }
- #pragma mark - Private Methods -
- - (NSURL *)encodedFileURLForKey:(NSString *)key
- {
- if (![key length])
- return nil;
-
- //Significantly improve performance by indicating that the URL will *not* result in a directory.
- //Also note that accessing _cacheURL is safe without the lock because it is only set on init.
- return [_cacheURL URLByAppendingPathComponent:[self encodedString:key] isDirectory:NO];
- }
- - (NSString *)keyForEncodedFileURL:(NSURL *)url
- {
- NSString *fileName = [url lastPathComponent];
- if (!fileName)
- return nil;
-
- return [self decodedString:fileName];
- }
- - (NSString *)encodedString:(NSString *)string
- {
- if (![string length]) {
- return @"";
- }
-
- if ([string respondsToSelector:@selector(stringByAddingPercentEncodingWithAllowedCharacters:)]) {
- NSString *encodedString = [string stringByAddingPercentEncodingWithAllowedCharacters:[[NSCharacterSet characterSetWithCharactersInString:@".:/%"] invertedSet]];
- if (self.fileExtension.length > 0) {
- return [encodedString stringByAppendingPathExtension:self.fileExtension];
- }
- else {
- return encodedString;
- }
- }
- else {
- CFStringRef static const charsToEscape = CFSTR(".:/%");
- #pragma clang diagnostic push
- #pragma clang diagnostic ignored "-Wdeprecated-declarations"
- CFStringRef escapedString = CFURLCreateStringByAddingPercentEscapes(kCFAllocatorDefault,
- (__bridge CFStringRef)string,
- NULL,
- charsToEscape,
- kCFStringEncodingUTF8);
- #pragma clang diagnostic pop
-
- if (self.fileExtension.length > 0) {
- return [(__bridge_transfer NSString *)escapedString stringByAppendingPathExtension:self.fileExtension];
- }
- else {
- return (__bridge_transfer NSString *)escapedString;
- }
- }
- }
- - (NSString *)decodedString:(NSString *)string
- {
- if (![string length]) {
- return @"";
- }
-
- if ([string respondsToSelector:@selector(stringByRemovingPercentEncoding)]) {
- return [string stringByRemovingPercentEncoding];
- }
- else {
- #pragma clang diagnostic push
- #pragma clang diagnostic ignored "-Wdeprecated-declarations"
- CFStringRef unescapedString = CFURLCreateStringByReplacingPercentEscapesUsingEncoding(kCFAllocatorDefault,
- (__bridge CFStringRef)string,
- CFSTR(""),
- kCFStringEncodingUTF8);
- #pragma clang diagnostic pop
- return (__bridge_transfer NSString *)unescapedString;
- }
- }
- -(PINDiskCacheSerializerBlock) defaultSerializer
- {
- return ^NSData*(id<NSCoding> object, NSString *key){
- return [NSKeyedArchiver archivedDataWithRootObject:object];
- };
- }
- -(PINDiskCacheDeserializerBlock) defaultDeserializer
- {
- return ^id(NSData * data, NSString *key){
- return [NSKeyedUnarchiver unarchiveObjectWithData:data];
- };
- }
- #pragma mark - Private Trash Methods -
- + (dispatch_queue_t)sharedTrashQueue
- {
- static dispatch_queue_t trashQueue;
- static dispatch_once_t predicate;
-
- dispatch_once(&predicate, ^{
- NSString *queueName = [[NSString alloc] initWithFormat:@"%@.trash", PINDiskCachePrefix];
- trashQueue = dispatch_queue_create([queueName UTF8String], DISPATCH_QUEUE_SERIAL);
- dispatch_set_target_queue(trashQueue, dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0));
- });
-
- return trashQueue;
- }
- + (NSLock *)sharedLock
- {
- static NSLock *sharedLock;
- static dispatch_once_t onceToken;
- dispatch_once(&onceToken, ^{
- sharedLock = [NSLock new];
- });
- return sharedLock;
- }
- + (NSURL *)sharedTrashURL
- {
- NSURL *trashURL = nil;
-
- [[PINDiskCache sharedLock] lock];
- if (_sharedTrashURL == nil) {
- NSString *uniqueString = [[NSProcessInfo processInfo] globallyUniqueString];
- _sharedTrashURL = [[[NSURL alloc] initFileURLWithPath:NSTemporaryDirectory()] URLByAppendingPathComponent:uniqueString isDirectory:YES];
-
- NSError *error = nil;
- [[NSFileManager defaultManager] createDirectoryAtURL:_sharedTrashURL
- withIntermediateDirectories:YES
- attributes:nil
- error:&error];
- PINDiskCacheError(error);
- }
- trashURL = _sharedTrashURL;
- [[PINDiskCache sharedLock] unlock];
-
- return trashURL;
- }
- + (BOOL)moveItemAtURLToTrash:(NSURL *)itemURL
- {
- if (![[NSFileManager defaultManager] fileExistsAtPath:[itemURL path]])
- return NO;
-
- NSError *error = nil;
- NSString *uniqueString = [[NSProcessInfo processInfo] globallyUniqueString];
- NSURL *uniqueTrashURL = [[PINDiskCache sharedTrashURL] URLByAppendingPathComponent:uniqueString isDirectory:NO];
- BOOL moved = [[NSFileManager defaultManager] moveItemAtURL:itemURL toURL:uniqueTrashURL error:&error];
- PINDiskCacheError(error);
- return moved;
- }
- + (void)emptyTrash
- {
- dispatch_async([PINDiskCache sharedTrashQueue], ^{
- NSURL *trashURL = nil;
-
- // If _sharedTrashURL is unset, there's nothing left to do because it hasn't been accessed and therefore items haven't been added to it.
- // If it is set, we can just remove it.
- // We also need to nil out _sharedTrashURL so that a new one will be created if there's an attempt to move a new file to the trash.
- [[PINDiskCache sharedLock] lock];
- if (_sharedTrashURL != nil) {
- trashURL = _sharedTrashURL;
- _sharedTrashURL = nil;
- }
- [[PINDiskCache sharedLock] unlock];
-
- if (trashURL != nil) {
- NSError *removeTrashedItemError = nil;
- [[NSFileManager defaultManager] removeItemAtURL:trashURL error:&removeTrashedItemError];
- PINDiskCacheError(removeTrashedItemError);
- }
- });
- }
- #pragma mark - Private Queue Methods -
- - (BOOL)_locked_createCacheDirectory
- {
- if ([[NSFileManager defaultManager] fileExistsAtPath:[_cacheURL path]])
- return NO;
-
- NSError *error = nil;
- BOOL success = [[NSFileManager defaultManager] createDirectoryAtURL:_cacheURL
- withIntermediateDirectories:YES
- attributes:nil
- error:&error];
- PINDiskCacheError(error);
-
- return success;
- }
- - (void)_locked_initializeDiskProperties
- {
- NSUInteger byteCount = 0;
- NSArray *keys = @[ NSURLContentModificationDateKey, NSURLTotalFileAllocatedSizeKey ];
-
- NSError *error = nil;
- NSArray *files = [[NSFileManager defaultManager] contentsOfDirectoryAtURL:_cacheURL
- includingPropertiesForKeys:keys
- options:NSDirectoryEnumerationSkipsHiddenFiles
- error:&error];
- PINDiskCacheError(error);
-
- for (NSURL *fileURL in files) {
- NSString *key = [self keyForEncodedFileURL:fileURL];
-
- error = nil;
- NSDictionary *dictionary = [fileURL resourceValuesForKeys:keys error:&error];
- PINDiskCacheError(error);
-
- NSDate *date = [dictionary objectForKey:NSURLContentModificationDateKey];
- if (date && key)
- [_dates setObject:date forKey:key];
-
- NSNumber *fileSize = [dictionary objectForKey:NSURLTotalFileAllocatedSizeKey];
- if (fileSize) {
- [_sizes setObject:fileSize forKey:key];
- byteCount += [fileSize unsignedIntegerValue];
- }
- }
-
- if (byteCount > 0)
- self.byteCount = byteCount; // atomic
- }
- - (void)asynchronouslySetFileModificationDate:(NSDate *)date forURL:(NSURL *)fileURL
- {
- __weak PINDiskCache *weakSelf = self;
- [self.operationQueue addOperation:^{
- PINDiskCache *strongSelf = weakSelf;
- if (strongSelf) {
- [strongSelf lock];
- [strongSelf _locked_setFileModificationDate:date forURL:fileURL];
- [strongSelf unlock];
- }
- } withPriority:PINOperationQueuePriorityLow];
- }
- - (BOOL)_locked_setFileModificationDate:(NSDate *)date forURL:(NSURL *)fileURL
- {
- if (!date || !fileURL) {
- return NO;
- }
-
- NSError *error = nil;
- BOOL success = [[NSFileManager defaultManager] setAttributes:@{ NSFileModificationDate: date }
- ofItemAtPath:[fileURL path]
- error:&error];
- PINDiskCacheError(error);
-
- if (success) {
- NSString *key = [self keyForEncodedFileURL:fileURL];
- if (key) {
- [_dates setObject:date forKey:key];
- }
- }
-
- return success;
- }
- - (BOOL)removeFileAndExecuteBlocksForKey:(NSString *)key
- {
- NSURL *fileURL = [self encodedFileURLForKey:key];
-
- [self lock];
- if (!fileURL || ![[NSFileManager defaultManager] fileExistsAtPath:[fileURL path]]) {
- [self unlock];
- return NO;
- }
-
- PINCacheObjectBlock willRemoveObjectBlock = _willRemoveObjectBlock;
- if (willRemoveObjectBlock) {
- [self unlock];
- willRemoveObjectBlock(self, key, nil);
- [self lock];
- }
-
- BOOL trashed = [PINDiskCache moveItemAtURLToTrash:fileURL];
- if (!trashed) {
- [self unlock];
- return NO;
- }
-
- [PINDiskCache emptyTrash];
-
- NSNumber *byteSize = [_sizes objectForKey:key];
- if (byteSize)
- self.byteCount = _byteCount - [byteSize unsignedIntegerValue]; // atomic
-
- [_sizes removeObjectForKey:key];
- [_dates removeObjectForKey:key];
-
- PINCacheObjectBlock didRemoveObjectBlock = _didRemoveObjectBlock;
- if (didRemoveObjectBlock) {
- [self unlock];
- _didRemoveObjectBlock(self, key, nil);
- [self lock];
- }
-
- [self unlock];
-
- return YES;
- }
- - (void)trimDiskToSize:(NSUInteger)trimByteCount
- {
- [self lock];
- if (_byteCount > trimByteCount) {
- NSArray *keysSortedBySize = [_sizes keysSortedByValueUsingSelector:@selector(compare:)];
-
- for (NSString *key in [keysSortedBySize reverseObjectEnumerator]) { // largest objects first
- [self unlock];
-
- //unlock, removeFileAndExecuteBlocksForKey handles locking itself
- [self removeFileAndExecuteBlocksForKey:key];
-
- [self lock];
-
- if (_byteCount <= trimByteCount)
- break;
- }
- }
- [self unlock];
- }
- - (void)trimDiskToSizeByDate:(NSUInteger)trimByteCount
- {
- [self lock];
- if (_byteCount > trimByteCount) {
- NSArray *keysSortedByDate = [_dates keysSortedByValueUsingSelector:@selector(compare:)];
-
- for (NSString *key in keysSortedByDate) { // oldest objects first
- [self unlock];
-
- //unlock, removeFileAndExecuteBlocksForKey handles locking itself
- [self removeFileAndExecuteBlocksForKey:key];
-
- [self lock];
-
- if (_byteCount <= trimByteCount)
- break;
- }
- }
- [self unlock];
- }
- - (void)trimDiskToDate:(NSDate *)trimDate
- {
- [self lock];
- NSArray *keysSortedByDate = [_dates keysSortedByValueUsingSelector:@selector(compare:)];
-
- for (NSString *key in keysSortedByDate) { // oldest files first
- NSDate *accessDate = [_dates objectForKey:key];
- if (!accessDate)
- continue;
-
- if ([accessDate compare:trimDate] == NSOrderedAscending) { // older than trim date
- [self unlock];
-
- //unlock, removeFileAndExecuteBlocksForKey handles locking itself
- [self removeFileAndExecuteBlocksForKey:key];
-
- [self lock];
- } else {
- break;
- }
- }
- [self unlock];
- }
- - (void)trimToAgeLimitRecursively
- {
- [self lock];
- NSTimeInterval ageLimit = _ageLimit;
- [self unlock];
- if (ageLimit == 0.0)
- return;
-
- NSDate *date = [[NSDate alloc] initWithTimeIntervalSinceNow:-ageLimit];
- [self trimDiskToDate:date];
-
- __weak PINDiskCache *weakSelf = self;
-
- dispatch_time_t time = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(_ageLimit * NSEC_PER_SEC));
- dispatch_after(time, dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^(void) {
- PINDiskCache *strongSelf = weakSelf;
- [strongSelf.operationQueue addOperation:^{
- PINDiskCache *strongSelf = weakSelf;
- [strongSelf trimToAgeLimitRecursively];
- } withPriority:PINOperationQueuePriorityLow];
- });
- }
- #pragma mark - Public Asynchronous Methods -
- - (void)lockFileAccessWhileExecutingBlockAsync:(PINCacheBlock)block
- {
- if (block == nil) {
- return;
- }
- __weak PINDiskCache *weakSelf = self;
-
- [self.operationQueue addOperation:^{
- PINDiskCache *strongSelf = weakSelf;
- [strongSelf lock];
- block(strongSelf);
- [strongSelf unlock];
- } withPriority:PINOperationQueuePriorityLow];
- }
- - (void)containsObjectForKeyAsync:(NSString *)key completion:(PINDiskCacheContainsBlock)block
- {
- if (!key || !block)
- return;
-
- __weak PINDiskCache *weakSelf = self;
-
- [self.operationQueue addOperation:^{
- PINDiskCache *strongSelf = weakSelf;
- block([strongSelf containsObjectForKey:key]);
- } withPriority:PINOperationQueuePriorityLow];
- }
- - (void)objectForKeyAsync:(NSString *)key completion:(PINDiskCacheObjectBlock)block
- {
- __weak PINDiskCache *weakSelf = self;
-
- [self.operationQueue addOperation:^{
- PINDiskCache *strongSelf = weakSelf;
- NSURL *fileURL = nil;
- id <NSCoding> object = [strongSelf objectForKey:key fileURL:&fileURL];
-
- block(strongSelf, key, object);
- } withPriority:PINOperationQueuePriorityLow];
- }
- - (void)fileURLForKeyAsync:(NSString *)key completion:(PINDiskCacheFileURLBlock)block
- {
- if (block == nil) {
- return;
- }
- __weak PINDiskCache *weakSelf = self;
-
- [self.operationQueue addOperation:^{
- PINDiskCache *strongSelf = weakSelf;
- NSURL *fileURL = [strongSelf fileURLForKey:key];
-
- [strongSelf lock];
- block(key, fileURL);
- [strongSelf unlock];
- } withPriority:PINOperationQueuePriorityLow];
- }
- - (void)setObjectAsync:(id <NSCoding>)object forKey:(NSString *)key completion:(PINDiskCacheObjectBlock)block
- {
- __weak PINDiskCache *weakSelf = self;
-
- [self.operationQueue addOperation:^{
- PINDiskCache *strongSelf = weakSelf;
- NSURL *fileURL = nil;
- [strongSelf setObject:object forKey:key fileURL:&fileURL];
-
- if (block) {
- block(strongSelf, key, object);
- }
- } withPriority:PINOperationQueuePriorityLow];
- }
- - (void)setObjectAsync:(id <NSCoding>)object forKey:(NSString *)key withCost:(NSUInteger)cost completion:(nullable PINCacheObjectBlock)block
- {
- [self setObjectAsync:object forKey:key completion:(PINDiskCacheObjectBlock)block];
- }
- - (void)removeObjectForKeyAsync:(NSString *)key completion:(PINDiskCacheObjectBlock)block
- {
- __weak PINDiskCache *weakSelf = self;
-
- [self.operationQueue addOperation:^{
- PINDiskCache *strongSelf = weakSelf;
- NSURL *fileURL = nil;
- [strongSelf removeObjectForKey:key fileURL:&fileURL];
-
- if (block) {
- block(strongSelf, key, nil);
- }
- } withPriority:PINOperationQueuePriorityLow];
- }
- - (void)trimToSizeAsync:(NSUInteger)trimByteCount completion:(PINCacheBlock)block
- {
- PINOperationBlock operation = ^(id data) {
- [self trimToSize:((NSNumber *)data).unsignedIntegerValue];
- };
-
- dispatch_block_t completion = nil;
- if (block) {
- completion = ^{
- block(self);
- };
- }
-
- [self.operationQueue addOperation:operation
- withPriority:PINOperationQueuePriorityLow
- identifier:PINDiskCacheOperationIdentifierTrimToSize
- coalescingData:[NSNumber numberWithUnsignedInteger:trimByteCount]
- dataCoalescingBlock:PINDiskTrimmingSizeCoalescingBlock
- completion:completion];
- }
- - (void)trimToDateAsync:(NSDate *)trimDate completion:(PINCacheBlock)block
- {
- PINOperationBlock operation = ^(id data){
- [self trimToDate:(NSDate *)data];
- };
-
- dispatch_block_t completion = nil;
- if (block) {
- completion = ^{
- block(self);
- };
- }
-
- [self.operationQueue addOperation:operation
- withPriority:PINOperationQueuePriorityLow
- identifier:PINDiskCacheOperationIdentifierTrimToDate
- coalescingData:trimDate
- dataCoalescingBlock:PINDiskTrimmingDateCoalescingBlock
- completion:completion];
- }
- - (void)trimToSizeByDateAsync:(NSUInteger)trimByteCount completion:(PINCacheBlock)block
- {
- PINOperationBlock operation = ^(id data){
- [self trimToSizeByDate:((NSNumber *)data).unsignedIntegerValue];
- };
-
- dispatch_block_t completion = nil;
- if (block) {
- completion = ^{
- block(self);
- };
- }
-
- [self.operationQueue addOperation:operation
- withPriority:PINOperationQueuePriorityLow
- identifier:PINDiskCacheOperationIdentifierTrimToSizeByDate
- coalescingData:[NSNumber numberWithUnsignedInteger:trimByteCount]
- dataCoalescingBlock:PINDiskTrimmingSizeCoalescingBlock
- completion:completion];
- }
- - (void)removeAllObjectsAsync:(PINCacheBlock)block
- {
- __weak PINDiskCache *weakSelf = self;
-
- [self.operationQueue addOperation:^{
- PINDiskCache *strongSelf = weakSelf;
- [strongSelf removeAllObjects];
-
- if (block) {
- block(strongSelf);
- }
- } withPriority:PINOperationQueuePriorityLow];
- }
- - (void)enumerateObjectsWithBlockAsync:(PINDiskCacheFileURLBlock)block completionBlock:(PINCacheBlock)completionBlock
- {
- __weak PINDiskCache *weakSelf = self;
-
- [self.operationQueue addOperation:^{
- PINDiskCache *strongSelf = weakSelf;
- [strongSelf enumerateObjectsWithBlock:block];
-
- if (completionBlock) {
- completionBlock(strongSelf);
- }
- } withPriority:PINOperationQueuePriorityLow];
- }
- #pragma mark - Public Synchronous Methods -
- - (void)synchronouslyLockFileAccessWhileExecutingBlock:(PINCacheBlock)block
- {
- if (block) {
- [self lock];
- block(self);
- [self unlock];
- }
- }
- - (BOOL)containsObjectForKey:(NSString *)key
- {
- return ([self fileURLForKey:key updateFileModificationDate:NO] != nil);
- }
- - (nullable id<NSCoding>)objectForKey:(NSString *)key
- {
- return [self objectForKey:key fileURL:nil];
- }
- - (id)objectForKeyedSubscript:(NSString *)key
- {
- return [self objectForKey:key];
- }
- - (nullable id <NSCoding>)objectForKey:(NSString *)key fileURL:(NSURL **)outFileURL
- {
- NSDate *now = [[NSDate alloc] init];
-
- if (!key)
- return nil;
-
- id <NSCoding> object = nil;
- NSURL *fileURL = [self encodedFileURLForKey:key];
-
- [self lock];
- if (!self->_ttlCache || self->_ageLimit <= 0 || fabs([[_dates objectForKey:key] timeIntervalSinceDate:now]) < self->_ageLimit) {
- // If the cache should behave like a TTL cache, then only fetch the object if there's a valid ageLimit and the object is still alive
- NSData *objectData = [[NSData alloc] initWithContentsOfFile:[fileURL path]];
-
- if (objectData) {
- //Be careful with locking below. We unlock here so that we're not locked while deserializing, we re-lock after.
- [self unlock];
- @try {
- object = _deserializer(objectData, key);
- }
- @catch (NSException *exception) {
- NSError *error = nil;
- [self lock];
- [[NSFileManager defaultManager] removeItemAtPath:[fileURL path] error:&error];
- [self unlock];
- PINDiskCacheError(error);
- }
- [self lock];
- }
- if (object && !self->_ttlCache) {
- [self asynchronouslySetFileModificationDate:now forURL:fileURL];
- }
- }
- [self unlock];
-
- if (outFileURL) {
- *outFileURL = fileURL;
- }
-
- return object;
- }
- /// Helper function to call fileURLForKey:updateFileModificationDate:
- - (NSURL *)fileURLForKey:(NSString *)key
- {
- // Don't update the file modification time, if self is a ttlCache
- return [self fileURLForKey:key updateFileModificationDate:!self->_ttlCache];
- }
- - (NSURL *)fileURLForKey:(NSString *)key updateFileModificationDate:(BOOL)updateFileModificationDate
- {
- if (!key) {
- return nil;
- }
-
- NSDate *now = [[NSDate alloc] init];
- NSURL *fileURL = [self encodedFileURLForKey:key];
-
- [self lock];
- if (fileURL.path && [[NSFileManager defaultManager] fileExistsAtPath:fileURL.path]) {
- if (updateFileModificationDate) {
- [self asynchronouslySetFileModificationDate:now forURL:fileURL];
- }
- } else {
- fileURL = nil;
- }
- [self unlock];
- return fileURL;
- }
- - (void)setObject:(id <NSCoding>)object forKey:(NSString *)key
- {
- [self setObject:object forKey:key fileURL:nil];
- }
- - (void)setObject:(id <NSCoding>)object forKey:(NSString *)key withCost:(NSUInteger)cost
- {
- [self setObject:object forKey:key];
- }
- - (void)setObject:(id)object forKeyedSubscript:(NSString *)key
- {
- if (object == nil) {
- [self removeObjectForKey:key];
- } else {
- [self setObject:object forKey:key];
- }
- }
- - (void)setObject:(id <NSCoding>)object forKey:(NSString *)key fileURL:(NSURL **)outFileURL
- {
- if (!key || !object)
- return;
-
- #if TARGET_OS_IPHONE
- NSDataWritingOptions writeOptions = NSDataWritingAtomic | self.writingProtectionOption;
- #else
- NSDataWritingOptions writeOptions = NSDataWritingAtomic;
- #endif
-
- NSURL *fileURL = [self encodedFileURLForKey:key];
-
- [self lock];
- PINCacheObjectBlock willAddObjectBlock = self->_willAddObjectBlock;
- if (willAddObjectBlock) {
- [self unlock];
- willAddObjectBlock(self, key, object);
- [self lock];
- }
-
- //We unlock here so that we're not locked while serializing.
- [self unlock];
- NSData *data = _serializer(object, key);
- [self lock];
-
- NSError *writeError = nil;
-
- BOOL written = [data writeToURL:fileURL options:writeOptions error:&writeError];
- PINDiskCacheError(writeError);
-
- if (written) {
- NSError *error = nil;
- NSDictionary *values = [fileURL resourceValuesForKeys:@[ NSURLContentModificationDateKey, NSURLTotalFileAllocatedSizeKey ] error:&error];
- PINDiskCacheError(error);
-
- NSNumber *diskFileSize = [values objectForKey:NSURLTotalFileAllocatedSizeKey];
- if (diskFileSize) {
- NSNumber *prevDiskFileSize = [self->_sizes objectForKey:key];
- if (prevDiskFileSize) {
- self.byteCount = self->_byteCount - [prevDiskFileSize unsignedIntegerValue];
- }
- [self->_sizes setObject:diskFileSize forKey:key];
- self.byteCount = self->_byteCount + [diskFileSize unsignedIntegerValue]; // atomic
- }
- NSDate *date = [values objectForKey:NSURLContentModificationDateKey];
- if (date) {
- [self->_dates setObject:date forKey:key];
- }
-
- if (self->_byteLimit > 0 && self->_byteCount > self->_byteLimit)
- [self trimToSizeByDateAsync:self->_byteLimit completion:nil];
- } else {
- fileURL = nil;
- }
-
- PINCacheObjectBlock didAddObjectBlock = self->_didAddObjectBlock;
- if (didAddObjectBlock) {
- [self unlock];
- didAddObjectBlock(self, key, object);
- [self lock];
- }
- [self unlock];
-
- if (outFileURL) {
- *outFileURL = fileURL;
- }
- }
- - (void)removeObjectForKey:(NSString *)key
- {
- [self removeObjectForKey:key fileURL:nil];
- }
- - (void)removeObjectForKey:(NSString *)key fileURL:(NSURL **)outFileURL
- {
- if (!key)
- return;
-
- NSURL *fileURL = nil;
-
- fileURL = [self encodedFileURLForKey:key];
-
- [self removeFileAndExecuteBlocksForKey:key];
-
- if (outFileURL) {
- *outFileURL = fileURL;
- }
- }
- - (void)trimToSize:(NSUInteger)trimByteCount
- {
- if (trimByteCount == 0) {
- [self removeAllObjects];
- return;
- }
-
- [self trimDiskToSize:trimByteCount];
- }
- - (void)trimToDate:(NSDate *)trimDate
- {
- if (!trimDate)
- return;
-
- if ([trimDate isEqualToDate:[NSDate distantPast]]) {
- [self removeAllObjects];
- return;
- }
-
- [self trimDiskToDate:trimDate];
- }
- - (void)trimToSizeByDate:(NSUInteger)trimByteCount
- {
- if (trimByteCount == 0) {
- [self removeAllObjects];
- return;
- }
-
- [self trimDiskToSizeByDate:trimByteCount];
- }
- - (void)removeAllObjects
- {
- [self lock];
- PINCacheBlock willRemoveAllObjectsBlock = self->_willRemoveAllObjectsBlock;
- if (willRemoveAllObjectsBlock) {
- [self unlock];
- willRemoveAllObjectsBlock(self);
- [self lock];
- }
-
- [PINDiskCache moveItemAtURLToTrash:self->_cacheURL];
- [PINDiskCache emptyTrash];
-
- [self _locked_createCacheDirectory];
-
- [self->_dates removeAllObjects];
- [self->_sizes removeAllObjects];
- self.byteCount = 0; // atomic
-
- PINCacheBlock didRemoveAllObjectsBlock = self->_didRemoveAllObjectsBlock;
- if (didRemoveAllObjectsBlock) {
- [self unlock];
- didRemoveAllObjectsBlock(self);
- [self lock];
- }
-
- [self unlock];
- }
- - (void)enumerateObjectsWithBlock:(PINDiskCacheFileURLBlock)block
- {
- if (!block)
- return;
-
- [self lock];
- NSDate *now = [NSDate date];
- NSArray *keysSortedByDate = [self->_dates keysSortedByValueUsingSelector:@selector(compare:)];
-
- for (NSString *key in keysSortedByDate) {
- NSURL *fileURL = [self encodedFileURLForKey:key];
- // If the cache should behave like a TTL cache, then only fetch the object if there's a valid ageLimit and the object is still alive
- if (!self->_ttlCache || self->_ageLimit <= 0 || fabs([[_dates objectForKey:key] timeIntervalSinceDate:now]) < self->_ageLimit) {
- block(key, fileURL);
- }
- }
- [self unlock];
- }
- #pragma mark - Public Thread Safe Accessors -
- - (PINDiskCacheObjectBlock)willAddObjectBlock
- {
- PINDiskCacheObjectBlock block = nil;
-
- [self lock];
- block = _willAddObjectBlock;
- [self unlock];
-
- return block;
- }
- - (void)setWillAddObjectBlock:(PINDiskCacheObjectBlock)block
- {
- __weak PINDiskCache *weakSelf = self;
-
- [self.operationQueue addOperation:^{
- PINDiskCache *strongSelf = weakSelf;
- if (!strongSelf)
- return;
- [strongSelf lock];
- strongSelf->_willAddObjectBlock = [block copy];
- [strongSelf unlock];
- } withPriority:PINOperationQueuePriorityHigh];
- }
- - (PINDiskCacheObjectBlock)willRemoveObjectBlock
- {
- PINDiskCacheObjectBlock block = nil;
-
- [self lock];
- block = _willRemoveObjectBlock;
- [self unlock];
-
- return block;
- }
- - (void)setWillRemoveObjectBlock:(PINDiskCacheObjectBlock)block
- {
- __weak PINDiskCache *weakSelf = self;
-
- [self.operationQueue addOperation:^{
- PINDiskCache *strongSelf = weakSelf;
- if (!strongSelf)
- return;
-
- [strongSelf lock];
- strongSelf->_willRemoveObjectBlock = [block copy];
- [strongSelf unlock];
- } withPriority:PINOperationQueuePriorityHigh];
- }
- - (PINCacheBlock)willRemoveAllObjectsBlock
- {
- PINCacheBlock block = nil;
-
- [self lock];
- block = _willRemoveAllObjectsBlock;
- [self unlock];
-
- return block;
- }
- - (void)setWillRemoveAllObjectsBlock:(PINCacheBlock)block
- {
- __weak PINDiskCache *weakSelf = self;
-
- [self.operationQueue addOperation:^{
- PINDiskCache *strongSelf = weakSelf;
- if (!strongSelf)
- return;
-
- [strongSelf lock];
- strongSelf->_willRemoveAllObjectsBlock = [block copy];
- [strongSelf unlock];
- } withPriority:PINOperationQueuePriorityHigh];
- }
- - (PINDiskCacheObjectBlock)didAddObjectBlock
- {
- PINDiskCacheObjectBlock block = nil;
-
- [self lock];
- block = _didAddObjectBlock;
- [self unlock];
-
- return block;
- }
- - (void)setDidAddObjectBlock:(PINDiskCacheObjectBlock)block
- {
- __weak PINDiskCache *weakSelf = self;
-
- [self.operationQueue addOperation:^{
- PINDiskCache *strongSelf = weakSelf;
- if (!strongSelf)
- return;
-
- [strongSelf lock];
- strongSelf->_didAddObjectBlock = [block copy];
- [strongSelf unlock];
- } withPriority:PINOperationQueuePriorityHigh];
- }
- - (PINDiskCacheObjectBlock)didRemoveObjectBlock
- {
- PINDiskCacheObjectBlock block = nil;
-
- [self lock];
- block = _didRemoveObjectBlock;
- [self unlock];
-
- return block;
- }
- - (void)setDidRemoveObjectBlock:(PINDiskCacheObjectBlock)block
- {
- __weak PINDiskCache *weakSelf = self;
-
- [self.operationQueue addOperation:^{
- PINDiskCache *strongSelf = weakSelf;
- if (!strongSelf)
- return;
-
- [strongSelf lock];
- strongSelf->_didRemoveObjectBlock = [block copy];
- [strongSelf unlock];
- } withPriority:PINOperationQueuePriorityHigh];
- }
- - (PINCacheBlock)didRemoveAllObjectsBlock
- {
- PINCacheBlock block = nil;
-
- [self lock];
- block = _didRemoveAllObjectsBlock;
- [self unlock];
-
- return block;
- }
- - (void)setDidRemoveAllObjectsBlock:(PINCacheBlock)block
- {
- __weak PINDiskCache *weakSelf = self;
-
- [self.operationQueue addOperation:^{
- PINDiskCache *strongSelf = weakSelf;
- if (!strongSelf)
- return;
-
- [strongSelf lock];
- strongSelf->_didRemoveAllObjectsBlock = [block copy];
- [strongSelf unlock];
- } withPriority:PINOperationQueuePriorityHigh];
- }
- - (NSUInteger)byteLimit
- {
- NSUInteger byteLimit;
-
- [self lock];
- byteLimit = _byteLimit;
- [self unlock];
-
- return byteLimit;
- }
- - (void)setByteLimit:(NSUInteger)byteLimit
- {
- __weak PINDiskCache *weakSelf = self;
-
- [self.operationQueue addOperation:^{
- PINDiskCache *strongSelf = weakSelf;
- if (!strongSelf)
- return;
-
- [strongSelf lock];
- strongSelf->_byteLimit = byteLimit;
- [strongSelf unlock];
-
- if (byteLimit > 0)
- [strongSelf trimDiskToSizeByDate:byteLimit];
- } withPriority:PINOperationQueuePriorityHigh];
- }
- - (NSTimeInterval)ageLimit
- {
- NSTimeInterval ageLimit;
-
- [self lock];
- ageLimit = _ageLimit;
- [self unlock];
-
- return ageLimit;
- }
- - (void)setAgeLimit:(NSTimeInterval)ageLimit
- {
- __weak PINDiskCache *weakSelf = self;
-
- [self.operationQueue addOperation:^{
- PINDiskCache *strongSelf = weakSelf;
- if (!strongSelf)
- return;
-
- [strongSelf lock];
- strongSelf->_ageLimit = ageLimit;
- [strongSelf unlock];
-
- [strongSelf trimToAgeLimitRecursively];
- } withPriority:PINOperationQueuePriorityHigh];
- }
- - (BOOL)isTTLCache {
- BOOL isTTLCache;
-
- [self lock];
- isTTLCache = _ttlCache;
- [self unlock];
-
- return isTTLCache;
- }
- - (void)setTtlCache:(BOOL)ttlCache {
- __weak PINDiskCache *weakSelf = self;
- [self.operationQueue addOperation:^{
- PINDiskCache *strongSelf = weakSelf;
- if (!strongSelf)
- return;
- [strongSelf lock];
- strongSelf->_ttlCache = ttlCache;
- [strongSelf unlock];
- } withPriority:PINOperationQueuePriorityHigh];
- }
- #if TARGET_OS_IPHONE
- - (NSDataWritingOptions)writingProtectionOption {
- NSDataWritingOptions option;
-
- [self lock];
- option = _writingProtectionOption;
- [self unlock];
-
- return option;
- }
- - (void)setWritingProtectionOption:(NSDataWritingOptions)writingProtectionOption {
- __weak PINDiskCache *weakSelf = self;
-
- [self.operationQueue addOperation:^{
- PINDiskCache *strongSelf = weakSelf;
- if (!strongSelf)
- return;
-
- NSDataWritingOptions option = NSDataWritingFileProtectionMask & writingProtectionOption;
-
- [strongSelf lock];
- strongSelf->_writingProtectionOption = option;
- [strongSelf unlock];
- } withPriority:PINOperationQueuePriorityHigh];
- }
- #endif
- - (void)lock
- {
- [_instanceLock lockWhenCondition:PINDiskCacheConditionReady];
- }
- - (void)unlock
- {
- [_instanceLock unlockWithCondition:PINDiskCacheConditionReady];
- }
- @end
- @implementation PINDiskCache (Deprecated)
- - (void)lockFileAccessWhileExecutingBlock:(nullable PINCacheBlock)block
- {
- [self lockFileAccessWhileExecutingBlockAsync:block];
- }
- - (void)containsObjectForKey:(NSString *)key block:(PINDiskCacheContainsBlock)block
- {
- [self containsObjectForKeyAsync:key completion:block];
- }
- - (void)objectForKey:(NSString *)key block:(nullable PINDiskCacheObjectBlock)block
- {
- [self objectForKeyAsync:key completion:block];
- }
- - (void)fileURLForKey:(NSString *)key block:(nullable PINDiskCacheFileURLBlock)block
- {
- [self fileURLForKeyAsync:key completion:block];
- }
- - (void)setObject:(id <NSCoding>)object forKey:(NSString *)key block:(nullable PINDiskCacheObjectBlock)block
- {
- [self setObjectAsync:object forKey:key completion:block];
- }
- - (void)removeObjectForKey:(NSString *)key block:(nullable PINDiskCacheObjectBlock)block
- {
- [self removeObjectForKeyAsync:key completion:block];
- }
- - (void)trimToDate:(NSDate *)date block:(nullable PINDiskCacheBlock)block
- {
- [self trimToDateAsync:date completion:block];
- }
- - (void)trimToSize:(NSUInteger)byteCount block:(nullable PINDiskCacheBlock)block
- {
- [self trimToSizeAsync:byteCount completion:block];
- }
- - (void)trimToSizeByDate:(NSUInteger)byteCount block:(nullable PINDiskCacheBlock)block
- {
- [self trimToSizeAsync:byteCount completion:block];
- }
- - (void)removeAllObjects:(nullable PINDiskCacheBlock)block
- {
- [self removeAllObjectsAsync:block];
- }
- - (void)enumerateObjectsWithBlock:(PINDiskCacheFileURLBlock)block completionBlock:(nullable PINDiskCacheBlock)completionBlock
- {
- [self enumerateObjectsWithBlockAsync:block completionBlock:completionBlock];
- }
- @end
|