cayenne-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Gary Jarrel <garyjar...@gmail.com>
Subject More on caching
Date Fri, 28 May 2010 06:20:48 GMT
Hi All

I'm still trying to wrap my head around the Cayenne caching system,
(maybe Friday afternoon isn't doing me any good)

I have a test case as follows:

public void testBasicSelectQueryWithoutDaoWithCache() {
    initCache();
    assertEquals(0, getDataContext().getQueryCache().size());

    SelectQuery q = new SelectQuery(Admin.class);
    q.setCacheGroups("testGroup");
    q.setCacheStrategy(QueryCacheStrategy.SHARED_CACHE);

    List<Admin> result = getDataContext().performQuery(q);
    assertEquals(2, result.size());

    SelectQuery q2 = new SelectQuery(Admin.class);
    List<Admin> result2 = getDataContext().performQuery(q2);
    assertEquals(2, result2.size());

    assertEquals(1, getDataContext().getQueryCache().size());
}

private void initCache() {
    DataContext context = (DataContext) getDataContext();
    DataDomain domain = context.getParentDataDomain();
    domain.setQueryCacheFactory(new OSQueryCacheFactory());
    domain.setSharedCacheEnabled(true);
    this.osCache = true;
}

I would expect that the the second query q2 would not execute any SQL
however the QueryLogger logs the second select statement.

Also the assert on the query cache size fails the it appears the size
is zero rather than 1 as I would have expected.

If I change the second call to performQuery to query q (List<Admin>
result2 = getDataContext().performQuery(q);) then in the log I get
DEBUG [AbstractConcurrentReadCache.java:694] => get called (key=Admin)
but the cache size in the last Assert is still 0 ???

I've read through the docs a few times and I can not see what I am doing wrong.

Thank you

Gary

Mime
View raw message