Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use Guava Cache to persist data to a hard disk

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.
like image 399
Iceglaze Avatar asked Nov 12 '14 10:11

Iceglaze


2 Answers

This will probably be helpful: Extending Guava caches to overflow to disk

like image 182
Chris Avatar answered Sep 30 '22 14:09

Chris


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.

like image 32
Enno Shioji Avatar answered Sep 30 '22 16:09

Enno Shioji