You are here: Symbol Reference
> dtSearch.Engine Namespace
> IndexCache Class
dtSearch .NET Standard API 2021.02
IndexCache Class

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

dtSearch.Engine.DisposableObject dtSearch.Engine.IndexCache
public class IndexCache : DisposableObject;

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 an IndexCache object; and
  2. Assign it to SearchJob.IndexCache before searching.
Cache Lifetime

An IndexCache uses unmanaged resources (the implementation of the index cache inside the dtSearch Engine) and therefore implements the IDisposable pattern. Either a using{} clause or a call to Dispose() is needed to ensure that these resources will be freed when the cache is no longer needed. 

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 AutoCloseTime to specify a maximum number of seconds before unused indexes are automatically closed. Another setting, AutoReopenTime, can be used to ensure that even heavily-used indexes are periodically closed and reopened to refresh their view of the index contents. 

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.


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.


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.


IndexCache requires the IDisposable Pattern.

Copyright (c) 1998-2021 dtSearch Corp. All rights reserved.