Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to create a read-through cache with Spring/Hibernate/etc
    primarykey
    data
    text
    <p>The Spring Cache abstraction allows you to easily cache the results of method but when it comes to collections, AFAIC, it just caches the collection result which is not always efficient when many users share elements in the collection.</p> <p>What I'm looking for is a good way to create a read-through cache. And I'm looking for some suggestions how best to do it. </p> <p>In this scenario I'm retrieving postsings from various users (imagine FB wall). The posts have aspects that are common for each user: title, description, photo of the poster etc. But also things that are individual to the user: "You and 3 of your friends like this."</p> <p>My Service Layer basically has methods such as this</p> <pre><code>public List&lt;Post&gt; getPosts(User user, int start, int max){ //get the ids List&lt;Long&gt; ids = dao.getPostIds(user, start, max); //get the associated posts List&lt;Post&gt; posts = dao.getPosts(ids); //personalize result return convert(posts, user); } </code></pre> <p>The Post objects are derivatives of the Hibernate managed Post Entity. I always feel that getting the entire Hibernate managed entity with all it's lazy collections and sometimes unwanted initialization is not the ideal candidate for large volume reads, so I project the values of those entities to a simple Post bean. If anyone has any thoughts on the sense of that it would be interesting also.</p> <p>PostIds are things that update very frequently as new posts come in. The posts themselves can be shared amongst users as you will see some of the same posts as your friends. Conversions are unique to the end user.</p> <p>So, I would like to be able the cache to support this. A short lived id cache and a LFU post cache. This is more or less the way that the second level Hibernate cache works, but unless someone can convince me otherwise, that's out. Also I want to use this a little higher up the chain so that we can cache objects and not just arrays of values that have to be hydrated to objects on each request.</p> <p>So, the LFU cache would have to be able to see if any of the id-posts are in its cache and retrieve any missing items from the database in a separate getPosts(ids) for the missing ones, put them in the cache and the whole thing returns a result.</p> <p>Is there a good way of doing this that doesn't require lots of wheels to be invented? Most if not all of the documentation seems to be focused on just caching the entire result of a method without some describing how to achieve this more fine grained read through approach.</p> <p>Any suggestions are appreciated.</p> <p>Kind regards, Marc</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload