Johnathan Au
Johnathan Au

Reputation: 5372

What is the load() method in Guava LoadingCache?

I am trying to implement the LoadingCache and in it I must override the load() method.

However, the documentation is a bit lacking and I can't seem to find any decent examples surrounding this. My questions for this are:

Upvotes: 4

Views: 5778

Answers (1)

Frank Pavageau
Frank Pavageau

Reputation: 11735

LoadingCache doesn't have a load() method, CacheLoader does. And if you read the CachesExplained page of the wiki in addition to the javadoc, I think there's plenty of documentation:

  • A LoadingCache will automatically compute values it doesn't already have (because they never were requested, or were evicted) when they are requested by key.
  • To do so, it delegates the computation to the CacheLoader which given a key, returns the value: that's the job of the V load(K key) method, the only abstract method of CacheLoader, the one you need to implement.

Upvotes: 4

Related Questions