-
Notifications
You must be signed in to change notification settings - Fork 361
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update enumeration methods to allow a stop flag to be flipped by caller #204
Changes from 3 commits
11ee57d
1c87c6a
a9c6320
9c96f0c
578d98d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -797,7 +797,7 @@ - (void)removeAllObjectsAsync:(PINCacheBlock)block | |
} withPriority:PINOperationQueuePriorityLow]; | ||
} | ||
|
||
- (void)enumerateObjectsWithBlockAsync:(PINDiskCacheFileURLBlock)block completionBlock:(PINCacheBlock)completionBlock | ||
- (void)enumerateObjectsWithBlockAsync:(PINDiskCacheFileURLEnumerationBlock)block completionBlock:(PINCacheBlock)completionBlock | ||
{ | ||
__weak PINDiskCache *weakSelf = self; | ||
|
||
|
@@ -1093,7 +1093,7 @@ - (void)removeAllObjects | |
[self unlock]; | ||
} | ||
|
||
- (void)enumerateObjectsWithBlock:(PINDiskCacheFileURLBlock)block | ||
- (void)enumerateObjectsWithBlock:(PINDiskCacheFileURLEnumerationBlock)block | ||
{ | ||
if (!block) | ||
return; | ||
|
@@ -1106,7 +1106,10 @@ - (void)enumerateObjectsWithBlock:(PINDiskCacheFileURLBlock)block | |
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); | ||
BOOL stop; | ||
block(key, fileURL, &stop); | ||
if (stop) | ||
break; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. super nit, but can you do 4 spaces here? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would recommend creating a .clang-format file containing your specific style rules. It works great with objc, and you could probably integrate it as a presubmit check on your CI. |
||
} | ||
} | ||
[self unlock]; | ||
|
@@ -1444,7 +1447,9 @@ - (void)removeAllObjects:(nullable PINDiskCacheBlock)block | |
|
||
- (void)enumerateObjectsWithBlock:(PINDiskCacheFileURLBlock)block completionBlock:(nullable PINDiskCacheBlock)completionBlock | ||
{ | ||
[self enumerateObjectsWithBlockAsync:block completionBlock:completionBlock]; | ||
[self enumerateObjectsWithBlockAsync:^(NSString * _Nonnull key, NSURL * _Nullable fileURL, BOOL * _Nonnull stop) { | ||
block(key, fileURL); | ||
} completionBlock:completionBlock]; | ||
} | ||
|
||
@end |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -395,7 +395,7 @@ - (void)removeAllObjectsAsync:(PINCacheBlock)block | |
} withPriority:PINOperationQueuePriorityHigh]; | ||
} | ||
|
||
- (void)enumerateObjectsWithBlockAsync:(PINCacheObjectBlock)block completionBlock:(PINCacheBlock)completionBlock | ||
- (void)enumerateObjectsWithBlockAsync:(PINCacheObjectEnumerationBlock)block completionBlock:(PINCacheBlock)completionBlock | ||
{ | ||
__weak PINMemoryCache *weakSelf = self; | ||
|
||
|
@@ -550,7 +550,7 @@ - (void)removeAllObjects | |
|
||
} | ||
|
||
- (void)enumerateObjectsWithBlock:(PINCacheObjectBlock)block | ||
- (void)enumerateObjectsWithBlock:(PINCacheObjectEnumerationBlock)block | ||
{ | ||
if (!block) | ||
return; | ||
|
@@ -562,7 +562,10 @@ - (void)enumerateObjectsWithBlock:(PINCacheObjectBlock)block | |
for (NSString *key in keysSortedByDate) { | ||
// 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(self, key, _dictionary[key]); | ||
BOOL stop; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this is unsafe? If the block doesn't set the stop value this will be garbage, not NO? I think only ivars are automatically initialized to zero? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Value types are always initialized to zero when they're allocated on the stack. Happy to change this to make it more readable though. |
||
block(self, key, _dictionary[key], &stop); | ||
if (stop) | ||
break; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 4 species please There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. |
||
} | ||
} | ||
[self unlock]; | ||
|
@@ -827,7 +830,12 @@ - (void)removeAllObjects:(nullable PINMemoryCacheBlock)block | |
|
||
- (void)enumerateObjectsWithBlock:(PINMemoryCacheObjectBlock)block completionBlock:(nullable PINMemoryCacheBlock)completionBlock | ||
{ | ||
[self enumerateObjectsWithBlockAsync:block completionBlock:completionBlock]; | ||
[self enumerateObjectsWithBlockAsync:^(id<PINCaching> _Nonnull cache, NSString * _Nonnull key, id _Nullable object, BOOL * _Nonnull stop) { | ||
if ([cache isKindOfClass:[PINMemoryCache class]]) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 4 space indentation (sorry) 😬 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. |
||
PINMemoryCache *memoryCache = (PINMemoryCache *)cache; | ||
block(memoryCache, key, object); | ||
} | ||
} completionBlock:completionBlock]; | ||
} | ||
|
||
@end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you initialize this to NO (same comment as below).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.