use of org.apache.ibatis.cache.decorators.ScheduledCache in project mybatis-3 by mybatis.
the class CacheBuilder method setStandardDecorators.
private Cache setStandardDecorators(Cache cache) {
try {
MetaObject metaCache = SystemMetaObject.forObject(cache);
if (size != null && metaCache.hasSetter("size")) {
metaCache.setValue("size", size);
}
if (clearInterval != null) {
cache = new ScheduledCache(cache);
((ScheduledCache) cache).setClearInterval(clearInterval);
}
if (readWrite) {
cache = new SerializedCache(cache);
}
cache = new LoggingCache(cache);
cache = new SynchronizedCache(cache);
if (blocking) {
cache = new BlockingCache(cache);
}
return cache;
} catch (Exception e) {
throw new CacheException("Error building standard cache decorators. Cause: " + e, e);
}
}
use of org.apache.ibatis.cache.decorators.ScheduledCache in project mybatis-3 by mybatis.
the class BaseCacheTest method shouldDemonstrateEqualsAndHashCodeForVariousCacheTypes.
@Test
public void shouldDemonstrateEqualsAndHashCodeForVariousCacheTypes() {
PerpetualCache cache = new PerpetualCache("test_cache");
assertTrue(cache.equals(cache));
assertTrue(cache.equals(new SynchronizedCache(cache)));
assertTrue(cache.equals(new SerializedCache(cache)));
assertTrue(cache.equals(new LoggingCache(cache)));
assertTrue(cache.equals(new ScheduledCache(cache)));
assertEquals(cache.hashCode(), new SynchronizedCache(cache).hashCode());
assertEquals(cache.hashCode(), new SerializedCache(cache).hashCode());
assertEquals(cache.hashCode(), new LoggingCache(cache).hashCode());
assertEquals(cache.hashCode(), new ScheduledCache(cache).hashCode());
Set<Cache> caches = new HashSet<Cache>();
caches.add(cache);
caches.add(new SynchronizedCache(cache));
caches.add(new SerializedCache(cache));
caches.add(new LoggingCache(cache));
caches.add(new ScheduledCache(cache));
assertEquals(1, caches.size());
}
use of org.apache.ibatis.cache.decorators.ScheduledCache 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());
}
use of org.apache.ibatis.cache.decorators.ScheduledCache 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));
}
use of org.apache.ibatis.cache.decorators.ScheduledCache 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));
}
Aggregations