EHCachingSearchCache { public IntObjectPair<List<UniqueId>> search(final Bean requestBean, PagingRequest pagingRequest, boolean blockUntilCached) { ArgumentChecker.notNull(requestBean, "requestBean"); ArgumentChecker.notNull(pagingRequest, "pagingRequest"); final IntObjectPair<ConcurrentNavigableMap<Integer, List<UniqueId>>> info = getCachedRequestInfo(requestBean, pagingRequest); final int totalResults = info.getFirstInt(); final ConcurrentNavigableMap<Integer, List<UniqueId>> rangeMap = info.getSecond(); if (pagingRequest.getFirstItem() >= totalResults) { pagingRequest = PagingRequest.ofIndex(totalResults, 0); } else if (pagingRequest.getLastItem() >= totalResults) { pagingRequest = PagingRequest.ofIndex(pagingRequest.getFirstItem(), totalResults - pagingRequest.getFirstItem()); } IntObjectPair<List<UniqueId>> pair = cacheSuperRange(requestBean, pagingRequest, rangeMap, totalResults, blockUntilCached); final int superIndex = pair.getFirstInt(); final List<UniqueId> superRange = pair.getSecond(); final List<UniqueId> resultUniqueIds = superRange.subList( pagingRequest.getFirstItem() - superIndex, Math.min(pagingRequest.getLastItem() - superIndex, superRange.size())); return IntObjectPair.of(totalResults, resultUniqueIds); } EHCachingSearchCache(String name, CacheManager cacheManager, Searcher searcher); IntObjectPair<List<UniqueId>> search(final Bean requestBean, PagingRequest pagingRequest,
                                                     boolean blockUntilCached); void prefetch(final Bean requestBean, PagingRequest pagingRequest); static List<UniqueId> extractUniqueIds(List<? extends UniqueIdentifiable> uniqueIdentifiables); static void cacheDocuments(List<? extends AbstractDocument> documents, Ehcache documentCache); static Bean withPagingRequest(final Bean requestBean, final PagingRequest pagingRequest); void shutdown(); Searcher getSearcher(); Ehcache getCache(); CacheManager getCacheManager(); ExecutorService getExecutorService(); static final boolean TEST_AGAINST_UNDERLYING; }
@Test public void testSearchCache() { for (int requestSize = 1; requestSize < TOTAL_SIZE; requestSize = requestSize + 17) { for (int requestStartStepSize = 1; requestStartStepSize < TOTAL_SIZE / 2; requestStartStepSize = requestStartStepSize + 71) { EHCachingSearchCache searchCache = getCleanSearchCache(); for (int requestStartPos = 0; requestStartPos * requestStartStepSize < TOTAL_SIZE * 4; requestStartPos++) { PagingRequest pagingRequest = PagingRequest.ofIndex((requestStartPos * requestStartStepSize) % TOTAL_SIZE, requestSize); assertEquals(searchCache.search(new SecuritySearchRequest(), pagingRequest, false).getSecond(), buildResultIDs( PagingRequest.ofIndex( pagingRequest.getFirstItem(), Math.min(pagingRequest.getLastItem() - pagingRequest.getFirstItem(), TOTAL_SIZE - pagingRequest.getFirstItem() ) ) ) ); } } } }