Use Guava Cache to persist data to a hard disk

2019-04-09 09:28发布

I am new to Guava Cache. How do I create the following in the cache?

  1. Save the data in memory as normal.
  2. When the size of the cache is over the given number, it will persist the data in cache in a configurable file on the hard disk.

2条回答
看我几分像从前
2楼-- · 2019-04-09 10:10
霸刀☆藐视天下
3楼-- · 2019-04-09 10:27

The API (and the feature set) is a bit heavy weight but I've used Ehcache in the past and it worked well. Similar technologies include Infinispan and Hazelcast.

I don't like the solution in the article Chris shared as performance and the storage limit will depend on the file system you run on (and won't be particularly good), and it also lacks protection against corruption etc. If you plan to use it in production, I'd use one of these libraries.

查看更多
登录 后发表回答