Search in sources :

Example 1 with QueryCacheKey

use of com.yahoo.prelude.cache.QueryCacheKey in project vespa by vespa-engine.

the class CachingSearcher method search.

public Result search(com.yahoo.search.Query query, Execution execution) {
    if (query.getNoCache()) {
        return execution.search(query);
    }
    QueryCacheKey queryKey = new QueryCacheKey(query);
    Result cachedResult = cache.get(queryKey);
    if (cachedResult != null) {
        cacheHit();
        return cachedResult;
    }
    cacheMiss();
    // Need a copy, as cache hash key later on, maybe.
    Query originalQuery = query.clone();
    Result result = execution.search(query);
    execution.fill(result);
    if (!noCacheWrite(query)) {
        // Because the query member has changed state
        queryKey.setQuery(originalQuery);
        cache.put(queryKey, result);
    }
    return result;
}
Also used : Query(com.yahoo.search.Query) QueryCacheKey(com.yahoo.prelude.cache.QueryCacheKey) Result(com.yahoo.search.Result)

Example 2 with QueryCacheKey

use of com.yahoo.prelude.cache.QueryCacheKey in project vespa by vespa-engine.

the class CacheTestCase method testInsertSame.

@Test
public void testInsertSame() {
    // 100 KB, .5 sec expire
    Cache cache = new Cache(100 * 1024, 500, 100000, Statistics.nullImplementation);
    Query q = new Query("/std_xmls_a00?hits=5&offset=5&query=flowers+shop&tracelevel=4&objid=ffffffffffffffff");
    Result r = getSomeResult(q, "foo");
    QueryCacheKey k = new QueryCacheKey(q);
    cache.put(k, r);
    assertEquals(1, cache.size());
    q = new Query("/std_xmls_a00?hits=5&offset=5&query=flowers+shop&tracelevel=4&objid=ffffffffffffffff");
    k = new QueryCacheKey(q);
    cache.put(k, r);
    assertEquals(1, cache.size());
}
Also used : Query(com.yahoo.search.Query) QueryCacheKey(com.yahoo.prelude.cache.QueryCacheKey) Cache(com.yahoo.prelude.cache.Cache) Result(com.yahoo.search.Result) Test(org.junit.Test)

Example 3 with QueryCacheKey

use of com.yahoo.prelude.cache.QueryCacheKey in project vespa by vespa-engine.

the class CacheTestCase method testBasicGet.

@Test
public void testBasicGet() {
    Cache<QueryCacheKey, Result> cache = new Cache<>(100 * 1024, 3600, 100000, Statistics.nullImplementation);
    Query q = new Query("/std_xmls_a00?hits=5&offset=5&query=flowers+shop&tracelevel=4&objid=ffffffffffffffff");
    Query q2 = new Query("/std_xmls_a00?hits=5&offset=5&query=flowers+shop&tracelevel=4&objid=ffffffffffffffff");
    QueryCacheKey qk = new QueryCacheKey(q);
    QueryCacheKey qk2 = new QueryCacheKey(q2);
    Result r = getSomeResult(q, "foo");
    Result r2 = getSomeResult(q, "bar");
    assertNull(cache.get(qk));
    cache.put(qk, r);
    assertNotNull(cache.get(qk));
    assertEquals(cache.get(qk), r);
    cache.put(qk2, r);
    assertEquals(cache.get(qk2), r);
    cache.put(qk, r2);
    assertEquals(cache.get(qk), r2);
}
Also used : Query(com.yahoo.search.Query) QueryCacheKey(com.yahoo.prelude.cache.QueryCacheKey) Result(com.yahoo.search.Result) Cache(com.yahoo.prelude.cache.Cache) Test(org.junit.Test)

Aggregations

QueryCacheKey (com.yahoo.prelude.cache.QueryCacheKey)3 Query (com.yahoo.search.Query)3 Result (com.yahoo.search.Result)3 Cache (com.yahoo.prelude.cache.Cache)2 Test (org.junit.Test)2