Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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:

  • What does it do?
  • When is it called?
  • How often is it called?
like image 963
Johnathan Au Avatar asked Oct 26 '25 03:10

Johnathan Au


1 Answers

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.
like image 162
Frank Pavageau Avatar answered Oct 28 '25 17:10

Frank Pavageau