NRTCachingDirectory
Wraps a RAM-resident directory around any provided delegate directory, to be used during NRT search.
This class is likely only useful in a near-real-time context, where indexing rate is lowish but reopen rate is highish, resulting in many tiny files being written. This directory keeps such segments (as well as the segments produced by merging them, as long as they are small enough), in RAM.
This is safe to use: when your app calls {IndexWriter#commit}, all cached files will be flushed from the cached and sync'd.
Here's a simple example usage:
Directory fsDir = FSDirectory.open(new File("/path/to/index").toPath());
NRTCachingDirectory cachedFSDir = new NRTCachingDirectory(fsDir, 5.0, 60.0);
IndexWriterConfig conf = new IndexWriterConfig(analyzer);
IndexWriter writer = new IndexWriter(cachedFSDir, conf);
This will cache all newly flushed segments, all merges whose expected segment size is {@code <= 5 MB}, unless the net cached bytes exceed 60 MB at which point all writes will not be cached (until the net bytes fall below 60 MB).
Properties
Functions
Creates a new, empty file in the directory and returns an IndexOutput instance for appending data to this file.
Creates a new, empty, temporary file in the directory and returns an IndexOutput instance for appending data to this file.
Removes an existing file in the directory.
Ensures this directory is still open.
Returns the byte length of a file in the directory.
Returns names of all files stored in this directory. The output must be in sorted (UTF-16, java's String.compareTo) order.
Acquires and returns a Lock for a file with the given name.
Opens a checksum-computing stream for reading an existing file.
Opens a stream for reading an existing file.
Return the memory usage of this object in bytes. Negative values are illegal.
Ensures that any writes to these files are moved to stable storage (made durable).
Ensures that directory metadata, such as recent file renames, are moved to stable storage.