Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8325415
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T00:25:47+00:00 2026-06-09T00:25:47+00:00

I am interested in knowing what is the effective way of loadAll method implementation

  • 0

I am interested in knowing what is the effective way of loadAll method implementation introduced in google guava 11.0 library.

Here is the following code that describes load all method implementation extended
as per the example from CachesExplained

LoadingCache<Key, Graph> graphs = CacheBuilder.newBuilder().maximumSize(1000)
.refreshAfterWrite(1, TimeUnit.MINUTES)
.build(
   new CacheLoader<Key, Graph>() {
     public Graph load(Key key) { // no checked exception
       return getGraphFromDatabase(key);
     }

     public Map<Key, Graph> loadAll(Iterable<? extends K> keys) {
         return getAllGraphsFromDatabase(keys);
     }
   }
);

private Map<Key, Graph> getAllGraphsFromDatabase(Iterable<? extends key> keys)
{
  lListOfGraph = //resultset got from DB Call
  for (lCount = 0; lCount < lListOfGraph.size(); lCount++)
  {
     lGraph = (Graph)lListOfGraph.get(lCount).get(0);
     graphs.asMap().put((key , lGraph);
  }
  return (Map<key, Graph>) graphs;
}

Here return type that is Map throws error java.lang.ClassCastException:com.google.common.cache.LocalCache$LocalLoadingCache cannot be cast to java.util.Map (Knowing the fact that Loading Cache object can not be of type Map)

If this is not the correct way of implementation of using LoadingCache then
How is the data injected in LoadingCache’s Component so that it can be used as Cache.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T00:25:48+00:00Added an answer on June 9, 2026 at 12:25 am

    Your getAllGraphsFromDatabase method should be fetching the values from the underlying data store. The LoadingCache implementation handles adding the returned values to the map for you.

    I think your loading method should look like:

    private Map<Key, Graph> getAllGraphsFromDatabase(Iterable<? extends key> keys)
    {
      final List<Graph> lListOfGraph = //resultset got from DB Call
    
      final Map<Key, Graph> map = new HashMap<Key, Graph>(listOfGraph.size());
      for (final Graph graph : lListOfGraph)
        map.put(graph.getKey(), graph);
    
      return map;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there a more efficient way to do the following? I am more interested
I am interested in knowing if the following scenario is a good use case
I am interested in knowing of a way to control web pages (preferably in
I am interested in knowing whether I can expect the observing object's method to
I have an object that is interested in knowing when the region of a
I am interested in knowing that what this private API do CGContextSetBaseCTM(CGContextRef c, CGAffineTransform
I am interested in knowing how databases handle connections that are not explicitly closed
I am interested in knowing about what other teams are doing about limiting internal
I'm interested in knowing what high quality and useful add-ons or utilities are available
I'm interested in knowing how revision-control systems do merging. Suppose you have a file

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.