I create a Cache use Caffeine.buider.build(), and put a CacheLoader in it.
Cache<Integer,String> cache = Caffeine.newBuilder()
.expireAfterWrite(10, TimeUnit.MINUTES)
.maximumSize(10000)
.build(this::getCache);
I ask ChatGPT, it told me that when I use cache.get(key)
method, and the key doesn’t exist, it will use CacheLoader to generate a ‘key-value’ and put it into cache then return from get
method.
But Caffeine doesn’t have a method cache.get(key)
, it only have cache.get(key,Function)
.
This method will use Function when the value of key doesn’t exist in Cache.
So,what is the purpose of passing a CacheLoader into the build() method during cache creation?
I ask ChatGPT, but it doesn’t give any useful information
AiChan is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.