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;
}
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());
}
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);
}
Aggregations