Search in sources :

Example 16 with PerpetualCache

use of org.apache.ibatis.cache.impl.PerpetualCache in project mybatis-3 by mybatis.

the class ScheduledCacheTest method shouldDemonstrateHowAllObjectsAreFlushedAfterBasedOnTime.

@Test
public void shouldDemonstrateHowAllObjectsAreFlushedAfterBasedOnTime() throws Exception {
    Cache cache = new PerpetualCache("DefaultCache");
    cache = new ScheduledCache(cache);
    ((ScheduledCache) cache).setClearInterval(2500);
    cache = new LoggingCache(cache);
    for (int i = 0; i < 100; i++) {
        cache.putObject(i, i);
        assertEquals(i, cache.getObject(i));
    }
    Thread.sleep(5000);
    assertEquals(0, cache.getSize());
}
Also used : PerpetualCache(org.apache.ibatis.cache.impl.PerpetualCache) ScheduledCache(org.apache.ibatis.cache.decorators.ScheduledCache) LoggingCache(org.apache.ibatis.cache.decorators.LoggingCache) LoggingCache(org.apache.ibatis.cache.decorators.LoggingCache) PerpetualCache(org.apache.ibatis.cache.impl.PerpetualCache) ScheduledCache(org.apache.ibatis.cache.decorators.ScheduledCache) Test(org.junit.Test)

Example 17 with PerpetualCache

use of org.apache.ibatis.cache.impl.PerpetualCache in project mybatis-3 by mybatis.

the class ScheduledCacheTest method shouldFlushAllItemsOnDemand.

@Test
public void shouldFlushAllItemsOnDemand() {
    Cache cache = new PerpetualCache("DefaultCache");
    cache = new ScheduledCache(cache);
    ((ScheduledCache) cache).setClearInterval(60000);
    cache = new LoggingCache(cache);
    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) ScheduledCache(org.apache.ibatis.cache.decorators.ScheduledCache) LoggingCache(org.apache.ibatis.cache.decorators.LoggingCache) LoggingCache(org.apache.ibatis.cache.decorators.LoggingCache) PerpetualCache(org.apache.ibatis.cache.impl.PerpetualCache) ScheduledCache(org.apache.ibatis.cache.decorators.ScheduledCache) Test(org.junit.Test)

Example 18 with PerpetualCache

use of org.apache.ibatis.cache.impl.PerpetualCache in project mybatis-3 by mybatis.

the class ScheduledCacheTest method shouldRemoveItemOnDemand.

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

Example 19 with PerpetualCache

use of org.apache.ibatis.cache.impl.PerpetualCache in project mybatis-3 by mybatis.

the class SoftCacheTest method shouldFlushAllItemsOnDemand.

@Test
public void shouldFlushAllItemsOnDemand() {
    Cache cache = new SoftCache(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) SoftCache(org.apache.ibatis.cache.decorators.SoftCache) SoftCache(org.apache.ibatis.cache.decorators.SoftCache) PerpetualCache(org.apache.ibatis.cache.impl.PerpetualCache) SerializedCache(org.apache.ibatis.cache.decorators.SerializedCache) Test(org.junit.Test)

Example 20 with PerpetualCache

use of org.apache.ibatis.cache.impl.PerpetualCache in project mybatis-3 by mybatis.

the class SoftCacheTest method shouldRemoveItemOnDemand.

@Test
public void shouldRemoveItemOnDemand() {
    Cache cache = new SoftCache(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) SoftCache(org.apache.ibatis.cache.decorators.SoftCache) SoftCache(org.apache.ibatis.cache.decorators.SoftCache) PerpetualCache(org.apache.ibatis.cache.impl.PerpetualCache) SerializedCache(org.apache.ibatis.cache.decorators.SerializedCache) Test(org.junit.Test)

Aggregations

PerpetualCache (org.apache.ibatis.cache.impl.PerpetualCache)27 Test (org.junit.Test)27 SerializedCache (org.apache.ibatis.cache.decorators.SerializedCache)9 SynchronizedCache (org.apache.ibatis.cache.decorators.SynchronizedCache)5 BaseDataTest (org.apache.ibatis.BaseDataTest)4 LoggingCache (org.apache.ibatis.cache.decorators.LoggingCache)4 ScheduledCache (org.apache.ibatis.cache.decorators.ScheduledCache)4 SoftCache (org.apache.ibatis.cache.decorators.SoftCache)4 WeakCache (org.apache.ibatis.cache.decorators.WeakCache)4 FifoCache (org.apache.ibatis.cache.decorators.FifoCache)3 LruCache (org.apache.ibatis.cache.decorators.LruCache)3 BindingException (org.apache.ibatis.binding.BindingException)2 TooManyResultsException (org.apache.ibatis.exceptions.TooManyResultsException)2 HashSet (java.util.HashSet)1