2 years later, are there now any ready solutions for this? I am already using jdbi-folder library to handle the one-to-many relationships between data-model objects so I assume the logic should be added somewhere inside folder?
Additional issue with folder is that between single and multiple returned objects, you'd always need to return FoldingList<YourType> because it's the FolderList that handles the joined tables.
--
You received this message because you are subscribed to the Google Groups "jDBI" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jdbi+uns...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
If you have a practical idea for what caching would look like in terms of annotations, I invite you to try writing, perhaps using Guava caches for the first attempt, to see if you can get something working.
I must warn you however, that I and at least one other team member are rather opposed to putting caching into JDBI proper. In my opinion that is where other ORMs go off the rails--caching is just too big a surface area to do it justice and still be flexible enough to adapt to all deployment environments. Consider the following:
* What is the life cycle of the cache? Global? Session? Request? Lifetime of DAO?
* What if we want to use a distributed cache?
* What key do we cache on? The list of all arguments? One argument in particular? A subset?
* How to expire cached elements? TTL? Time since last read?
* How do we limit the cache so it doesn't use too much memory? How do we decide which elements to discard when we're getting close to the limit?
* How can we make it so calling one method invalidates an item in the cache? e.g. we might want the cache behind MyDao.selectFooById(long) to be invalidated by a call to MyDao.update(Foo). How do we express that in annotations? How can we invalidate only the item for Foo.getId()?
* What if what happens in one DAO needs to invalidate items cached by a different DAO?
* How do we protect the cached elements from external modification by callers after they receive the data from the DAO call? Serialization / deserialization? Cloning?
This is just the beginning of the Gordian knot that is caching in ORMs. It is very difficult to come up with a design that will please everyone.
My approach to caching has been to plug it in a level above the DAO. e.g. hide MyDAO behind MyService with the same methods, and take care of caching by hand in the service class.
If you can come up with a clean design that addresses my concerns I would be happy to entertain a PR, so long as the proposed solution is opt-in.
I recommend working off the jdbi3 branch as that is where the action is at these days.
Good luck. Feel free to pose questions on the mailing list if you run into problems.
-Matt