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 (3.0 release) #2456

Closed
pjfanning opened this issue Sep 14, 2019 · 9 comments
Closed

new LookupCache interface (3.0 release) #2456

pjfanning opened this issue Sep 14, 2019 · 9 comments
Labels
3.x Issues to be only tackled for Jackson 3.x, not 2.x

Comments

@pjfanning
Copy link
Member

Aim is to allow the the type cache implementation to be pluggable.

SimpleLookupCache is the default implementation. Users can write their own implementaions based on other caching frameworks, like Caffeine, if they prefer. Jackson-databind having an interface means that we can have pluggability and not introduce new jar dependencies.

@cowtowncoder cowtowncoder added the 3.x Issues to be only tackled for Jackson 3.x, not 2.x label Sep 14, 2019
@cowtowncoder
Copy link
Member

Sounds good -- I add this on my WIP list of things. May take a while only as I am furiously trying to close 2.10 functionality, otherwise I think should be quick to go through.

@pjfanning
Copy link
Member Author

@ben-manes
Copy link

ben-manes commented Sep 14, 2019

@pjfanning Why not return the results from the asMap write methods instead of performing a get first?

@pjfanning
Copy link
Member Author

@ben-manes good point - I had left those lines behind from an earlier iteration

@cowtowncoder
Copy link
Member

@pjfanning Neat (wrt Caffeine-based impl). Would be nice to document somehow -- one of many things discussed at some point was that of how to support "Jackson Util" or "Jackson Ext", some form of place to contain helpful implementations, outside of core components but in usable form. For some things could be source go copy, for others small jar.

@cowtowncoder
Copy link
Member

So, I merged the PR, but got to thinking on part of how to make things configurable.
Immediately there are couple of questions:

  1. For many cases, it might be sufficient to just change max size -- but not same for all uses
  2. It may be necessary to provide a "supplier" (factory) of caches, not cache instance
  3. There are a few places and potential explosion in state, even if using ObjectMapper.Builder()

So then I realized that maybe, instead of making individual cache things configurable separate, there ought to be something like CacheProvider (or -Supplier or even Caches to follow naming semi-convention)? It would have separate named method for all distinct cache types we need (possibly with suggested max size? not sure about this); and there would be a default implementation just provides SimpleLookupCache instances. Idea would be to sub-class it, override what is needed.
Default implementation could have some amount of configurability wrt sizes.
Or perhaps we'd have both default implementation and simple "Base" that makes all other methods by default call a single abstract method: this to be used as base-class for custom implementations.
Either way, doing this would allow addition of new cache types in provider over time, without having to add new things in ObjectMapper.Builder.

One secondary benefit would be to sort of document all caches Jackson databind uses.
Custom providers could not only add more optimal cache implementations, but also support metrics generation, for most advanced use case.

@pjfanning
Copy link
Member Author

I guess it's best to come back to this after the 2.10.0 release is complete. I do favour the idea of being able to set a CacheProvider implementation in the MapperBuilder and us providing a default that uses SimpleLookupCache.

@cowtowncoder
Copy link
Member

Yes, agreed. I just wanted to write down broad idea I had, so I won't forget :)

@cowtowncoder
Copy link
Member

Created #2502 for the follow-up part.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3.x Issues to be only tackled for Jackson 3.x, not 2.x
Projects
None yet
Development

No branches or pull requests

3 participants