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

new LookupCache interface #2455

Merged
merged 6 commits into from
Sep 17, 2019
Merged

Conversation

pjfanning
Copy link
Member

@pjfanning pjfanning commented Sep 14, 2019

For #2456

public interface LookupCache <K,V>
extends Snapshottable<LookupCache<K,V>>,
java.io.Serializable {
void contents(BiConsumer<K,V> consumer);
Copy link
Member

Choose a reason for hiding this comment

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

Would be good to add Javadocs in general. But especially here, as to if and why iteration over entries is desired for all implementations.

Copy link
Member Author

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

Ah. Hmmh. Yes, that makes sense then... if that specific case is to be made pluggable.

Actually: let's drop that from interface, and not make this particular cache pluggable.
So contents() is perfectly fine for SimpleLookupCache for now. We can consider adding it into interface later on if other use is needed, but for now I'd rather keep API minimalistic.

int size();

/**
* NOTE: key is of type Object only to retain binary backwards-compatibility
Copy link
Member

Choose a reason for hiding this comment

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

Is that needed?

Copy link
Member Author

Choose a reason for hiding this comment

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

I kept this from existing SimpleLookupCache documentation

Copy link
Member

Choose a reason for hiding this comment

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

Ok. We wouldn't have to retain that (binary compatibility not preserved across 2.x -> 3.0 boundary) but... I don't feel strongly either way. I know that casting to type variable here won't be of much use as it's truly generic type. But it might help catch some type mismatches.

So I am fine either way at this point.

*/
public interface LookupCache <K,V>
extends Snapshottable<LookupCache<K,V>>,
java.io.Serializable {
Copy link
Member

Choose a reason for hiding this comment

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

Not sure java.io.Serializable is actually needed for interface itself.
Serializability in 3.0 is by serializing Builders. Although it may be true that for some types, implementations would need to be serializable. Snapshottable does make sense, I think.

@cowtowncoder
Copy link
Member

Makes sense; added some notes.

@pjfanning
Copy link
Member Author

@cowtowncoder my original intent was to support overriding the type cache in TypeFactory but the LookupCache is used in a few places (eg SerializerCache and DeserializerCache). These caches are not normally created by users directly. If we want to allow these caches to be able to use alternative cache implementations, would you have any suggestions? Maybe, we could expose something in the JsonMapper.Builder?

UnlimitedLookupCache<Object, JavaType> cache = new UnlimitedLookupCache<>(4, 10);
TypeFactory tf = TypeFactory.defaultInstance().withCache(cache);

//TODO find way to inject the `tf` instance into an ObjectMapper (via MapperBuilder?)
Copy link
Member Author

Choose a reason for hiding this comment

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

@cowtowncoder any suggestions on best place to do this?

Copy link
Member

Choose a reason for hiding this comment

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

Best place to... ? Inject cache?

Builder is the new mechanism, in general, but in case of TypeFactory I think it is reasonable that caller would need to create and configure it directly, pass instance.

Copy link
Member

Choose a reason for hiding this comment

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

For other caches, however, need to think about it... they are held on to by DeserializationContext / SerializerProvider, and we'd ideally avoid making developers create instances of those.

@cowtowncoder
Copy link
Member

How about I'll merge this, and initially comment out contents() -- we can revisit the issue.

@cowtowncoder cowtowncoder merged commit 3e8d4ae into FasterXML:master Sep 17, 2019
@cowtowncoder
Copy link
Member

Ok so I commented it out, but realized that... maybe that's not the way to go. May expose it back.

However. I also had another idea that might nicely complement this initial part. Will add notes to main issue.

@pjfanning pjfanning deleted the lookup-cache branch September 17, 2019 19:49
@pjfanning pjfanning changed the title WIP: new LookupCache interface new LookupCache interface Sep 17, 2019
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.

2 participants