Created
May 29, 2013 20:02
-
-
Save maltzsama/5673391 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| - (void)trimDiskToDate:(NSDate *)trimDate | |
| { | |
| 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 removeFileAndExecuteBlocksForKey:key]; | |
| } else { | |
| break; | |
| } | |
| } | |
| } | |
| - (void)trimToAgeLimitRecursively | |
| { | |
| if (_ageLimit == 0.0) | |
| return; | |
| NSDate *date = [[NSDate alloc] initWithTimeIntervalSinceNow:-_ageLimit]; | |
| [self trimDiskToDate:date]; | |
| __weak TMDiskCache *weakSelf = self; | |
| dispatch_time_t time = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(_ageLimit * NSEC_PER_SEC)); | |
| dispatch_after(time, _queue, ^(void) { | |
| TMDiskCache *strongSelf = weakSelf; | |
| [strongSelf trimToAgeLimitRecursively]; | |
| }); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment