Search in sources :

Example 1 with SimpleCacheHandler

use of com.github.drinkjava2.jdbpro.handler.SimpleCacheHandler in project jSqlBox by drinkjava2.

the class HandlersTest method testSimpleCacheHandler.

@Test
public void testSimpleCacheHandler() {
    for (int i = 0; i < 10; i++) {
        // warm up
        ctx.nQuery(new Wrap(new EntityListHandler(DemoUser.class), new SimpleCacheHandler()), "select u.** from DemoUser u where u.age>?", 0);
        ctx.nQuery(new Wrap(new EntityListHandler(DemoUser.class)), "select u.** from DemoUser u where u.age>?", 0);
    }
    long start = System.currentTimeMillis();
    for (int i = 0; i < 1000; i++) {
        List<DemoUser> result = ctx.nQuery(new Wrap(new EntityListHandler(DemoUser.class), new SimpleCacheHandler()), "select u.** from DemoUser u where u.age>?", 0);
        Assert.assertTrue(result.size() == 99);
    }
    long end = System.currentTimeMillis();
    String timeused = "" + (end - start) / 1000 + "." + (end - start) % 1000;
    System.out.println(String.format("%28s: %6s s", "With Cache", timeused));
    start = System.currentTimeMillis();
    for (int i = 0; i < 1000; i++) {
        List<DemoUser> result = ctx.nQuery(new Wrap(new EntityListHandler(DemoUser.class)), "select u.** from DemoUser u where u.age>?", 0);
        Assert.assertTrue(result.size() == 99);
    }
    end = System.currentTimeMillis();
    timeused = "" + (end - start) / 1000 + "." + (end - start) % 1000;
    System.out.println(String.format("%28s: %6s s", "No Cache", timeused));
}
Also used : Wrap(com.github.drinkjava2.jdbpro.handler.Wrap) SimpleCacheHandler(com.github.drinkjava2.jdbpro.handler.SimpleCacheHandler) EntityListHandler(com.github.drinkjava2.jsqlbox.handler.EntityListHandler) Test(org.junit.Test)

Aggregations

SimpleCacheHandler (com.github.drinkjava2.jdbpro.handler.SimpleCacheHandler)1 Wrap (com.github.drinkjava2.jdbpro.handler.Wrap)1 EntityListHandler (com.github.drinkjava2.jsqlbox.handler.EntityListHandler)1 Test (org.junit.Test)1