Pre-load values for a Guava Cache

后端 未结 2 657
予麋鹿
予麋鹿 2021-02-07 00:54

I have a requirement where we are loading static data from a database for use in a Java application. Any caching mechanism should have the following functionality:

相关标签:
2条回答
  • 2021-02-07 01:11

    In the short-term I would just use Cache.asMap().putAll(Map<K, V>).

    Once Guava 11.0 is released you can use Cache.getAll(Iterable<K>), which will issue a single bulk request for all absent elements.

    0 讨论(0)
  • 2021-02-07 01:20

    I'd load all static data from the DB, and store it in the Cache using cache.asMap().put(key, value) ([Guava 10.0.1 allows write operations on the Cache.asMap() view][1]).

    Of course, this static data might get evicted, if your cache is configured to evict entries...

    The CachePopulator idea is interesting.

    0 讨论(0)
提交回复
热议问题