Skip to content
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

added a way to set custom key encoder/decoder #192

Merged
merged 5 commits into from
Jun 16, 2017

Conversation

hovox
Copy link
Contributor

@hovox hovox commented Jun 14, 2017

Hi.
First, thanks for an amazing project. We are using ASDK and PINRemoteImage extensively in our app. We started to use PINCache as separate cache and there are cases when we want our custom filenames. We have added block for custom custom encoding/decoding, so anyone can provide their implementation for filenames. This can be used also for file extensions. Maybe in the next version extension can be replaced with custom blocks. Please let us know if it’s okey to merge.
Thanks.

@ghost
Copy link

ghost commented Jun 15, 2017

🚫 CI failed with log

Copy link
Collaborator

@garrettmoon garrettmoon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for putting this up! It would be great to get rid of the fileExtension as part of this PR, now is the perfect time since we're close to a big release!



/**
Multiple instances with the same name are allowed and can safely access
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeesh, this is no longer true, do you mind changing the first sentence to:

Multiple instances with the same name are *not* allowed and can *not* safely access the same data on disk.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the same needs to be done above to

@@ -39,7 +39,17 @@ - (instancetype)initWithName:(NSString *)name rootPath:(NSString *)rootPath file
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
- (instancetype)initWithName:(NSString *)name rootPath:(NSString *)rootPath serializer:(PINDiskCacheSerializerBlock)serializer deserializer:(PINDiskCacheDeserializerBlock)deserializer fileExtension:(NSString *)fileExtension {
return [self initWithName:name rootPath:rootPath serializer:serializer deserializer:deserializer keyEncoder:NULL keyDecoder:NULL fileExtension:fileExtension];
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: blocks are now objects so these should be nil, not NULL I believe?

rootPath:rootPath
serializer:serializer
deserializer:deserializer
keyEncoder:NULL
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here

rootPath:rootPath
serializer:serializer
deserializer:deserializer
keyEncoder:NULL
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: indentation and NULL instead of nil

}

- (instancetype)initWithName:(NSString *)name
prefix:(NSString *)prefix
rootPath:(NSString *)rootPath
serializer:(PINDiskCacheSerializerBlock)serializer
deserializer:(PINDiskCacheDeserializerBlock)deserializer
keyEncoder:(PINDiskCacheKeyEncoderBlock)keyEncoder
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: indentation

@@ -129,6 +142,12 @@ - (instancetype)initWithName:(NSString *)name
return nil;
}

if ((keyEncoder && !keyDecoder) ||
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of throwing an exception, can you use NSAssert?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I made like in serializer/deserializer case above. Should I change both to NSAssert ?


//setup key encoder/decoder
if(keyEncoder) {
_keyEncoder = [keyEncoder copy];
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think the copy is necessary anymore, but I'm ok with leaving it.

{
return ^NSData*(id<NSCoding> object, NSString *key){
return [NSKeyedArchiver archivedDataWithRootObject:object];
};
}

-(PINDiskCacheDeserializerBlock) defaultDeserializer
- (PINDiskCacheDeserializerBlock)defaultDeserializer
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the cleanup :)

@garrettmoon
Copy link
Collaborator

@hovox Do you mind adding an entry to the CHANGELOG.md file?

@ghost
Copy link

ghost commented Jun 15, 2017

🚫 CI failed with log

@hovox
Copy link
Contributor Author

hovox commented Jun 15, 2017

Should I remove fileExtension from the initializer ? What about API breakage ?

…ception into NSAssert, changed NULL to nil, fixed indentions.
@ghost
Copy link

ghost commented Jun 15, 2017

🚫 CI failed with log

@hovox
Copy link
Contributor Author

hovox commented Jun 15, 2017

All tests are passed on my machine.

@hovox
Copy link
Contributor Author

hovox commented Jun 15, 2017

@garrettmoon I have removed file extension, please let me know if it's okey.

@garrettmoon
Copy link
Collaborator

@hovox awesome, thank you for the PR!
@alexanderedge before we merge this in, wanted to get your thoughts on adding this in favor of file extension.

@alexanderedge
Copy link
Contributor

Thanks @garrettmoon for taking the time to let me know. This looks like a great PR and I have no issue moving to the more flexible solution using key encoders/decoders.

@garrettmoon
Copy link
Collaborator

Awesome, let's do this!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants