-
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
Update enumeration methods to allow a stop flag to be flipped by caller #204
Conversation
🚫 CI failed with log |
Source/PINMemoryCache.m
Outdated
@@ -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 comment
The 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 comment
The 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.
Source/PINDiskCache.m
Outdated
@@ -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; |
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.
Source/PINDiskCache.m
Outdated
BOOL stop; | ||
block(key, fileURL, &stop); | ||
if (stop) | ||
break; |
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.
super nit, but can you do 4 spaces here?
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.
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.
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.
Source/PINMemoryCache.m
Outdated
BOOL stop; | ||
block(self, key, _dictionary[key], &stop); | ||
if (stop) | ||
break; |
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.
4 species please
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.
Source/PINMemoryCache.m
Outdated
@@ -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 comment
The 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 comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
Thank you for the contribution, this will be super useful! |
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.
This will be really great to have!
@garrettmoon This will basically be a breaking API change, should we add a new API for it or go with it?
@maicki I think go for it because we're still in beta territory? |
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.
Thank you for the contribution @mjlazar !
No description provided.