Close
dtSearch Engine API for Java
IndexCache Class

An index cache keeps a pool of indexes open for faster searching

File: IndexCache.java 

Package: com.dtsearch.engine 

Syntax
Java
public class IndexCache;

An index cache can make searching substantially faster when a series of searches must be executed against a small number of indexes. The index cache maintains a pool of open indexes that will be available for searching on any thread. This eliminates the need to open and close the indexes being searched for every search request.

How to use an index cache
  1. Create a com.dtsearch.engine.IndexCache object
  2. Call SearchJob.setIndexCache to assign the cache to a SearchJob
Cache Lifetime

An application should generally create a single index cache before executing its first search, and should delete the index cache only after the last search is done and the last search results object has been deleted. 

Deleting an IndexCache object while a search is executing can cause a crash or a memory leak. Additionally, a search results object inherits the cache used in a search, so all search results objects must also be deleted before deleting the index cache.

Index Lifetime

To prevent indexes from remaining in the cache indefinitely, use IndexCache.AutoCloseTime to specify a maximum number of seconds before unused indexes are automatically closed. Another setting, IndexCache.AutoReopenTime, can be used to ensure that even heavily-used indexes are periodically closed and reopened to refresh their view of the index contents. Set IndexCache.AutoReopenTime to -1 to require a check on every search whether the index was modified since it was last opened. 

The cache does not have its own thread to implement AutoCloseTime or AutoReopenTime, so it only checks AutoCloseTime and AutoReopenTime when the cache is accessed for any reason, including a calls to read the OpenIndexCount and InUseCount properties.

Threading

Index caches are thread-safe, so any number of concurrent searches can share a single IndexCache. 

The same index may be open any number of times in an index cache. For example, if you have three concurrent threads searching c:\SampleIndex, and if the cache size is set to three indexes, then the cache will contain three open indexes all referencing c:\SampleIndex.

Performance

A search job will try to obtain each index to search from the cache. If an open index is available, the search job will use it for the duration of the search and return it to the cache when the search is done. 

If an index cache does not have any available indexes for a search, the search will create its own private open index to process the search, just as it would have done if there was no index cache. Therefore, attaching an index cache to a search job will not cause the search to fail due to an insufficient cache size, nor can it make searching slower than it would be without a cache.

com.dtsearch.engine.IndexCache