Java multithreaded cache for objects that are hard to create?

I need to cache some objects with rather hard creation times, and I need exactly one creation semantics. It should be possible to simultaneously create objects for different CacheKeys. I think I need something that (under the hood) does something like this:

ConcurrentHashMap<CacheKey, Future<HeavyObject>>

Are there existing open source versions that I can reuse?

+3
source share
2 answers

Have you looked at the Guava MapMaker class? I think he will do everything you need - although instead Futureyou provide a class a Function<? super K, ? extends V>, which is used to calculate the value.

, , , - , .

+3

- java-, Ehcache JBoss Cache.

( Infinispan), . - "-".

0

Source: https://habr.com/ru/post/1744099/


All Articles