Announcement Announcement Module
Collapse
No announcement yet.
Element-Level caching of collections Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Element-Level caching of collections

    Hi,

    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.

    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.

    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."

    My Service Layer basically has methods such as this
    PHP Code:
    public List<PostgetPosts(User userint startint max){
       
    //get the ids 
       
    List<Longids dao.getPostIds(userstartmax);

       
    //get the associated posts
       
    List<Postposts dao.getPosts(ids);

       
    //personalize result
       
    return convert(postsuser);

    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.

    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 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 converted to objects on each request.

    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.

    Is there a boiler plate way of doing this? 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 approach.

    Any suggestions are appreciated.

    Kind regards,
    Marc

  • #2
    bump

    Anyone? bump

    Comment

    Working...
    X