Pre-load values for a Guava Cache

后端 未结 2 660
予麋鹿
予麋鹿 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: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.

提交回复
热议问题