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);
}
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));
}
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));
}
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));
}
}
Aggregations