I was about to suggest that you follow Eric's idea of ββa database and learn how databases manage their buffers, effectively implementing their own virtual memory management.
But since I thought about it more, I came to the conclusion that most operating systems already perform better file system caching than you can probably do without low-level access in Java.
There is one lesson from database buffer management that you can consider. Databases use an understanding of the query plan to optimize management strategies.
In a relational database, it is often best to strip the most frequently used block from the cache. For example, a βyoungβ block containing a child record in a connection will not be displayed again, while a block containing its parent record is still in use, even if it is βolderβ.
On the other hand, operating system file caches are optimized for reusing recently used data (and reading before the last used data). If your application does not match this pattern, it may be worth managing the cache yourself.
source share