Example usage for org.apache.ibatis.cache Cache getObject

List of usage examples for org.apache.ibatis.cache Cache getObject

Introduction

In this page you can find the example usage for org.apache.ibatis.cache Cache getObject.

Prototype

Object getObject(Object key);

Source Link

Usage

From source file:com.github.ibole.infrastructure.persistence.db.mybatis.pagination.PaginationInterceptor.java

License:Apache License

private Integer getCount(String sql, Executor executor, MappedStatement ms, RowBounds rowBounds,
        BoundSql boundSql, Object parameter, Dialect dialect) throws SQLException {
    Integer count = 0;/*from  w ww.  j  av  a2 s .c  om*/
    Cache cache = ms.getCache();
    if (cache != null && ms.isUseCache() && ms.getConfiguration().isCacheEnabled()) {
        CacheKey cacheKey = executor.createCacheKey(ms, parameter, rowBounds, boundSql);
        count = (Integer) cache.getObject(cacheKey);
        if (count == null) {
            count = SqlHelper.getCount(sql, ms, executor.getTransaction(), parameter, boundSql, dialect);
            cache.putObject(cacheKey, count);
        }
    } else {
        count = SqlHelper.getCount(sql, ms, executor.getTransaction(), parameter, boundSql, dialect);
    }
    return count;
}

From source file:org.mybatis.caches.hazelcast.BaseHazelcastTestCase.java

License:Apache License

@Test
public void shouldDemonstrateHowAllObjectsAreKept() {
    Cache cache = newCache();
    for (int i = 0; i < 100000; i++) {
        cache.putObject(i, i);/*from   w w  w.j  ava 2s .c  o  m*/
        assertEquals(i, cache.getObject(i));
    }
    assertEquals(100000, cache.getSize());
}

From source file:org.mybatis.caches.hazelcast.BaseHazelcastTestCase.java

License:Apache License

@Test
public void shouldDemonstrateCopiesAreEqual() {
    Cache cache = newCache();
    for (int i = 0; i < 1000; i++) {
        cache.putObject(i, i);//from w w w.j ava2 s.com
        assertEquals(i, cache.getObject(i));
    }
}

From source file:org.mybatis.caches.hazelcast.BaseHazelcastTestCase.java

License:Apache License

@Test
public void shouldRemoveItemOnDemand() {
    Cache cache = newCache();
    cache.putObject(0, 0);/*  w  w w  .  j  ava2s.c o m*/
    assertNotNull(cache.getObject(0));
    cache.removeObject(0);
    assertNull(cache.getObject(0));
}

From source file:org.mybatis.caches.hazelcast.BaseHazelcastTestCase.java

License:Apache License

@Test
public void shouldFlushAllItemsOnDemand() {
    Cache cache = newCache();
    for (int i = 0; i < 5; i++) {
        cache.putObject(i, i);//  ww w.ja  v a  2 s  . c  o  m
    }
    assertNotNull(cache.getObject(0));
    assertNotNull(cache.getObject(4));
    cache.clear();
    assertNull(cache.getObject(0));
    assertNull(cache.getObject(4));
}