Search in sources :

Example 1 with Cache

use of com.yahoo.prelude.cache.Cache 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 2 with Cache

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

the class CacheTestCase method testInvalidateLRU.

@Test
public void testInvalidateLRU() {
    // 10 MB
    Cache cache = new Cache(10 * 1024, 3600, 100 * 1024, Statistics.nullImplementation);
    byte[] fiveKB = new byte[5 * 1024];
    for (int i = 0; i < 5 * 1024; i++) {
        fiveKB[i] = 127;
    }
    byte[] twoKB = new byte[2 * 1024];
    for (int i = 0; i < 2 * 1024; i++) {
        twoKB[i] = 127;
    }
    byte[] fourKB = new byte[4 * 1024];
    for (int i = 0; i < 4 * 1024; i++) {
        fourKB[i] = 127;
    }
    assertTrue(cache.put("five", fiveKB));
    assertTrue(cache.put("two", twoKB));
    // Makes two LRU
    Object dummy = cache.get("five");
    assertEquals(dummy, fiveKB);
    assertTrue(cache.put("four", fourKB));
    assertNull(cache.get("two"));
    assertEquals(cache.get("five"), fiveKB);
    assertEquals(cache.get("four"), fourKB);
    // Same, without the access, just to check
    // 10 KB
    cache = new Cache(10 * 1024, 3600, 100 * 1024, Statistics.nullImplementation);
    assertTrue(cache.put("five", fiveKB));
    assertTrue(cache.put("two", twoKB));
    assertTrue(cache.put("four", fourKB));
    assertEquals(cache.get("two"), twoKB);
    assertNull(cache.get("five"));
    assertEquals(cache.get("four"), fourKB);
}
Also used : Cache(com.yahoo.prelude.cache.Cache) Test(org.junit.Test)

Example 3 with Cache

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

the class CacheTestCase method testPutSameKey.

@Test
public void testPutSameKey() {
    // 10 MB
    Cache cache = new Cache(10 * 1024, 3600, 100 * 1024, Statistics.nullImplementation);
    byte[] fiveKB = new byte[5 * 1024];
    for (int i = 0; i < 5 * 1024; i++) {
        fiveKB[i] = 127;
    }
    byte[] twoKB = new byte[2 * 1024];
    for (int i = 0; i < 2 * 1024; i++) {
        twoKB[i] = 127;
    }
    byte[] fourKB = new byte[4 * 1024];
    for (int i = 0; i < 4 * 1024; i++) {
        fourKB[i] = 127;
    }
    assertTrue(cache.put("five", fiveKB));
    assertTrue(cache.put("two", twoKB));
    assertEquals(cache.get("two"), twoKB);
    assertEquals(cache.get("five"), fiveKB);
    assertTrue(cache.put("five", twoKB));
    assertEquals(cache.get("five"), twoKB);
    assertEquals(cache.get("two"), twoKB);
}
Also used : Cache(com.yahoo.prelude.cache.Cache) Test(org.junit.Test)

Example 4 with Cache

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

the class CacheTestCase method testMaxSize.

@Test
public void testMaxSize() {
    Cache cache = new Cache(20 * 1024, 500, 3 * 1024, Statistics.nullImplementation);
    byte[] fourKB = new byte[4 * 1024];
    for (int i = 0; i < 4 * 1024; i++) {
        fourKB[i] = 127;
    }
    byte[] twoKB = new byte[2 * 1024];
    for (int i = 0; i < 2 * 1024; i++) {
        twoKB[i] = 127;
    }
    assertFalse(cache.put("four", fourKB));
    assertTrue(cache.put("two", twoKB));
    assertNull(cache.get("four"));
    assertNotNull(cache.get("two"));
}
Also used : Cache(com.yahoo.prelude.cache.Cache) Test(org.junit.Test)

Example 5 with Cache

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

the class CacheTestCase method testInvalidate.

@Test
public void testInvalidate() {
    byte[] tenKB = new byte[10 * 1024];
    for (int i = 0; i < 10 * 1024; i++) {
        tenKB[i] = 127;
    }
    byte[] sevenKB = new byte[7 * 1024];
    for (int i = 0; i < 7 * 1024; i++) {
        sevenKB[i] = 127;
    }
    // 11 KB
    Cache cache = new Cache(11 * 1024, 3600, 100 * 1024, Statistics.nullImplementation);
    assertTrue(cache.put("foo", sevenKB));
    assertTrue(cache.put("bar", tenKB));
    assertNull(cache.get("foo"));
    assertEquals(cache.get("bar"), tenKB);
}
Also used : Cache(com.yahoo.prelude.cache.Cache) Test(org.junit.Test)

Aggregations

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