Is there a Java library that can cache data in memory or on disk depending on the size of the data?

Is there a way to write something to the buffer, but as soon as the buffer becomes large, start writing to the file?

I would like the whole process to be automatic. Basically, I would like to write to the buffer and have a library to make sure that I don't have enough memory.

I never want to block the recording process. If the buffer is too large, the library should write part of it to disk.

Does anyone know such a library?

Grae

The main thing is that I want to write only to disk when necessary. Data should be stored in memory, if buffer size allows.

+4
source share
3 answers

The Heritix project includes the RecordingOutputStream class. From javadocs:

RecordingOutputStream uses a built-in buffer and a backup disk file so that it can record streams of arbitrary length, limited only by available disk space.

As long as the recorded stream is smaller than the buffer in memory, there will be no access to the disk.

You can look at the source code to find out how this is achieved.

+4
source

EHCache does just that. All you have to do is configure it so that when it holds a certain limit of objects, they will be automatically deleted to disk storage

+2
source

@Grae: what is your application server ... maybe your application server provides such functionality. eg. if your application server is a websphere application server, then you can use the dyna caching services provided by WAS and use the "Disk Unload" function. Read more: WAS cache

0
source

All Articles