Further on Cache Groups

From: Gary Jarrel (garyjarre..mail.com)
Date: Mon May 31 2010 - 02:44:06 UTC

  • Next message: Gary Jarrel: "Pervasive & Cayenne"

    Hi All!

    Another interesting thing that I have just come across in relation to
    cache grouping and to continue on Bob's thread "Removing Cayenne cache
    groups" I have the following two test cases.

    @SuppressWarnings("unchecked")
    public void testBasicSelectQueryWithoutDaoWithSharedCache() {
        QueryCache domainCache = getSharedCache();
        QueryCache contextCache = getLocalCache();

        // this is one in the shared cache
        assertEquals(0, domainCache.size());

        // this is 0 in the local cache
        assertEquals(0, contextCache.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());

        // this is one in the shared cache
        assertEquals(1, domainCache.size());

        // this is 0 in the local cache
        assertEquals(0, contextCache.size());
    }

    @SuppressWarnings("unchecked")
    public void testBasicSelectQueryWithoutDaoWithLocalCache() {
        QueryCache domainCache = getSharedCache();
        QueryCache contextCache = getLocalCache();

        // this is one in the shared cache
        assertEquals(0, domainCache.size());

        // this is 0 in the local cache
        assertEquals(0, contextCache.size());

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

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

        // this is one in the shared cache
        assertEquals(0, domainCache.size());

        // this is 0 in the local cache
        assertEquals(1, contextCache.size());
    }

    and the following initialization method that runs before each test case.

    private void initCache() {
        DataContext context = (DataContext) getDataContext();
        DataDomain domain = context.getParentDataDomain();

        domain.setQueryCacheFactory(new OSQueryCacheFactory());
        domain.setSharedCacheEnabled(true);
        this.osCache = true;

        QueryCache localCache = getLocalCache();
        QueryCache sharedCache = getSharedCache();

        sharedCache.clear();
        localCache.clear();

        sharedCache.removeGroup("testGroup");
        localCache.removeGroup("testGroup");

        if (osCache) {
            OSQueryCache sharedOSCache = (OSQueryCache) sharedCache;
            sharedOSCache.getOsCache().removeEntry("testGroup");
            //sharedOSCache.getOsCache().removeEntry("Admin");
        }
    }

    When run one by one the test cases succeed fine. However when run all
    together the second test case fails on the following line at the very
    start:

    // this is one in the shared cache
    assertEquals(0, domainCache.size());

    This will happen if I keep the last line of the init method commented
    out which is:

    sharedOSCache.getOsCache().removeEntry("Admin");

    As soon as the line is uncommented then everything runs fine. This is
    despite the fact that I am removing my testGroup before each test
    case.

    Any thoughts?

    Thank you

    Gary



    This archive was generated by hypermail 2.0.0 : Mon May 31 2010 - 02:44:41 UTC