Search in sources :

Example 1 with WeakCache

use of org.apache.ibatis.cache.decorators.WeakCache in project mybatis-3 by mybatis.

the class WeakCacheTest method shouldDemonstrateObjectsBeingCollectedAsNeeded.

@Test
public void shouldDemonstrateObjectsBeingCollectedAsNeeded() {
    final int N = 3000000;
    WeakCache cache = new WeakCache(new PerpetualCache("default"));
    for (int i = 0; i < N; i++) {
        cache.putObject(i, i);
        if (cache.getSize() < i + 1) {
            //System.out.println("Cache exceeded with " + (i + 1) + " entries.");
            break;
        }
        if ((i + 1) % 100000 == 0) {
            // Try performing GC.
            System.gc();
        }
    }
    assertTrue(cache.getSize() < N);
}
Also used : PerpetualCache(org.apache.ibatis.cache.impl.PerpetualCache) WeakCache(org.apache.ibatis.cache.decorators.WeakCache) Test(org.junit.Test)

Example 2 with WeakCache

use of org.apache.ibatis.cache.decorators.WeakCache in project mybatis-3 by mybatis.

the class WeakCacheTest method shouldFlushAllItemsOnDemand.

@Test
public void shouldFlushAllItemsOnDemand() {
    WeakCache cache = new WeakCache(new PerpetualCache("default"));
    for (int i = 0; i < 5; i++) {
        cache.putObject(i, i);
    }
    assertNotNull(cache.getObject(0));
    assertNotNull(cache.getObject(4));
    cache.clear();
    assertNull(cache.getObject(0));
    assertNull(cache.getObject(4));
}
Also used : PerpetualCache(org.apache.ibatis.cache.impl.PerpetualCache) WeakCache(org.apache.ibatis.cache.decorators.WeakCache) Test(org.junit.Test)

Example 3 with WeakCache

use of org.apache.ibatis.cache.decorators.WeakCache in project mybatis-3 by mybatis.

the class WeakCacheTest method shouldRemoveItemOnDemand.

@Test
public void shouldRemoveItemOnDemand() {
    WeakCache cache = new WeakCache(new PerpetualCache("default"));
    cache.putObject(0, 0);
    assertNotNull(cache.getObject(0));
    cache.removeObject(0);
    assertNull(cache.getObject(0));
}
Also used : PerpetualCache(org.apache.ibatis.cache.impl.PerpetualCache) WeakCache(org.apache.ibatis.cache.decorators.WeakCache) Test(org.junit.Test)

Example 4 with WeakCache

use of org.apache.ibatis.cache.decorators.WeakCache in project mybatis-3 by mybatis.

the class WeakCacheTest method shouldDemonstrateCopiesAreEqual.

@Test
public void shouldDemonstrateCopiesAreEqual() {
    Cache cache = new WeakCache(new PerpetualCache("default"));
    cache = new SerializedCache(cache);
    for (int i = 0; i < 1000; i++) {
        cache.putObject(i, i);
        Object value = cache.getObject(i);
        assertTrue(value == null || value.equals(i));
    }
}
Also used : PerpetualCache(org.apache.ibatis.cache.impl.PerpetualCache) WeakCache(org.apache.ibatis.cache.decorators.WeakCache) SerializedCache(org.apache.ibatis.cache.decorators.SerializedCache) PerpetualCache(org.apache.ibatis.cache.impl.PerpetualCache) WeakCache(org.apache.ibatis.cache.decorators.WeakCache) SerializedCache(org.apache.ibatis.cache.decorators.SerializedCache) Test(org.junit.Test)

Aggregations

WeakCache (org.apache.ibatis.cache.decorators.WeakCache)4 PerpetualCache (org.apache.ibatis.cache.impl.PerpetualCache)4 Test (org.junit.Test)4 SerializedCache (org.apache.ibatis.cache.decorators.SerializedCache)1