Close
dtSearch Text Retrieval Engine Programmer's Reference
dtsIndexCache Class

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

File: dtsIndexCache.h 

Namespace: dtSearch 

Syntax
C++
class dtsIndexCache;

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 dtsIndexCache object (you will need to #include <dtsIndexCache.h>);
  2. Use dtsIndexCache::getHandle() to get a handle to the cache, and assign this handle to dtsSearchJob.indexCacheHandle; and
  3. Set up the dtsSearchJob and execute the search.
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 a dtsIndexCache 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 dtsIndexCacheOptions.autoCloseTime to specify a maximum number of seconds before unused indexes are automatically closed. Another setting, dtsIndexCacheOptions.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 call to dtsIndexCache.GetStatus().

Threading

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

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.

dtSearch::dtsIndexCache