GC_
GC_

Reputation: 1673

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

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.

Upvotes: 5

Views: 1755

Answers (3)

ag112
ag112

Reputation: 5687

@Grae: what is your app server...may be your app server provides such functionality.. for e.g. if your app server is websphere application server, then you can use dyna cache services provided by WAS and use "Disk offload" feature of it. More detail:WAS cache

Upvotes: 0

Kico Lobo
Kico Lobo

Reputation: 4404

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

Upvotes: 2

Brandon E Taylor
Brandon E Taylor

Reputation: 25359

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.

Upvotes: 4

Related Questions