Is the a way to write something to a buffer, but once the buffer gets to large, start writing to a file?
I would like this whole process to be automatic. Basically, I would like to write to a buffer, and have the library make sure I don't run out of memory.
I never want to block the writing process. If the buffer gets too large the library should write some of it to disk.
Does anyone know a library like that?
Grae
The main point is that I only want to write to disk when I have to. The data should be kept in memory if buffer size permits.
JCache API (JSR 107)JCache is a Java API for caching. It provides a set of common interfaces and classes that can be used to temporarily store Java objects in memory. It is a JCP standard represented by JSR 107.
The Java Object Cache is an in-process, process-wide caching service for general application use. That is, objects are cached within the process memory space, and the Java Object Cache is a single service that is shared by all threads running in the process, in contrast to a service that runs in another process.
Memory objects are Java objects that the Java Object Cache manages. Memory objects are stored in the Java VM's heap space as Java objects.
There are four types of caching are as follows: In-memory Caching. Database Caching. Web server Caching.
The Heritix project includes a class called RecordingOutputStream. From the javadocs:
The RecordingOutputStream uses an in-memory buffer and backing disk file to allow it to record streams of arbitrary length limited only by available disk space.
As long as the stream recorded is smaller than the in-memory buffer, no disk access will occur.
You can take a look at the source code to find out how this is achieved.
EHCache does exactly that. All you need to do is configure it so that when it holds a certain limit of objects, they'll be automatically flushed to the disk storage
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With