Store a large array on disk and access it randomly with caching.
Writing an array to disk
const diskArray = ;const path = ;const DIRECTORY_PATH = path;const array = 10 9 8 7;const options = elementsPerFile: 100;diskArray;
Reading from an array on disk
const diskArray = ;const path = ;const DIRECTORY_PATH = path;const MAX_CACHED_PAGES = 100;const cache = MAX_CACHED_PAGES;diskArray;
Creating a disk array simply breaks up your array into chunks and writes them to separate files as newline-separated JSON elements. Getting an element from the array retrieves it from the cache or loads it from disk if necessary. When the cache reaches max size, pages will be ejected from the cache in order of when they were last accessed. You can load multiple arrays with the same cache and they will share the cache.