Search in sources :

Example 11 with PerpetualCache

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

the class FifoCacheTest method shouldRemoveFirstItemInBeyondFiveEntries.

@Test
public void shouldRemoveFirstItemInBeyondFiveEntries() {
    FifoCache cache = new FifoCache(new PerpetualCache("default"));
    cache.setSize(5);
    for (int i = 0; i < 5; i++) {
        cache.putObject(i, i);
    }
    assertEquals(0, cache.getObject(0));
    cache.putObject(5, 5);
    assertNull(cache.getObject(0));
    assertEquals(5, cache.getSize());
}
Also used : PerpetualCache(org.apache.ibatis.cache.impl.PerpetualCache) FifoCache(org.apache.ibatis.cache.decorators.FifoCache) Test(org.junit.Test)

Example 12 with PerpetualCache

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

the class LruCacheTest method shouldRemoveItemOnDemand.

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

Example 13 with PerpetualCache

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

the class LruCacheTest method shouldRemoveLeastRecentlyUsedItemInBeyondFiveEntries.

@Test
public void shouldRemoveLeastRecentlyUsedItemInBeyondFiveEntries() {
    LruCache cache = new LruCache(new PerpetualCache("default"));
    cache.setSize(5);
    for (int i = 0; i < 5; i++) {
        cache.putObject(i, i);
    }
    assertEquals(0, cache.getObject(0));
    cache.putObject(5, 5);
    assertNull(cache.getObject(1));
    assertEquals(5, cache.getSize());
}
Also used : PerpetualCache(org.apache.ibatis.cache.impl.PerpetualCache) LruCache(org.apache.ibatis.cache.decorators.LruCache) Test(org.junit.Test)

Example 14 with PerpetualCache

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

the class PerpetualCacheTest method shouldDemonstrateHowAllObjectsAreKept.

@Test
public void shouldDemonstrateHowAllObjectsAreKept() {
    Cache cache = new PerpetualCache("default");
    cache = new SynchronizedCache(cache);
    for (int i = 0; i < 100000; i++) {
        cache.putObject(i, i);
        assertEquals(i, cache.getObject(i));
    }
    assertEquals(100000, cache.getSize());
}
Also used : PerpetualCache(org.apache.ibatis.cache.impl.PerpetualCache) SynchronizedCache(org.apache.ibatis.cache.decorators.SynchronizedCache) PerpetualCache(org.apache.ibatis.cache.impl.PerpetualCache) SynchronizedCache(org.apache.ibatis.cache.decorators.SynchronizedCache) SerializedCache(org.apache.ibatis.cache.decorators.SerializedCache) Test(org.junit.Test)

Example 15 with PerpetualCache

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

the class PerpetualCacheTest method shouldDemonstrateCopiesAreEqual.

@Test
public void shouldDemonstrateCopiesAreEqual() {
    Cache cache = new PerpetualCache("default");
    cache = new SerializedCache(cache);
    for (int i = 0; i < 1000; i++) {
        cache.putObject(i, i);
        assertEquals(i, cache.getObject(i));
    }
}
Also used : PerpetualCache(org.apache.ibatis.cache.impl.PerpetualCache) SerializedCache(org.apache.ibatis.cache.decorators.SerializedCache) PerpetualCache(org.apache.ibatis.cache.impl.PerpetualCache) SynchronizedCache(org.apache.ibatis.cache.decorators.SynchronizedCache) 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