Java cache objects to disk
<p>I have a collection of rather large objects (one complex class, can be made serializable) and an algorithm operating on it. The algorithm has to work on each object several times, and only needs a few objects of the collection at once.</p>

<p>To save RAM, I'd like to cache objects that weren't used for a while by the algorithm to disk if there isn't enough memory anymore. The algorithm needs to know which objects are on disk so it can avoid them as long as possible.</p>

<p>How do I achieve this? Do I have to implement this on my own or are there existing libraries?</p>

<p><strong>Edit:</strong></p>

<p>I probably won't have more than a few hundred of those objects since I discard them as soon as possible. Each object (simplified description) contains a 2D-array with up to 256x256 elements. Consider an average load of the main Array around about 30% and the child array being nearly full most of the time. Each object in the array contains some smaller data: A few array lists with vectors in it, a properties HashMap and so on. I outsourced most of the data with instancing so that it is fairly small.</p>