use of com.alicp.jetcache.support.DefaultCacheMonitorManager in project jetcache by alibaba.
the class MultiLevelCacheTest method doMonitoredTest.
private void doMonitoredTest(int expireMillis, Runnable test) {
initL1L2(expireMillis);
DefaultCacheMonitor m1 = new DefaultCacheMonitor("l1");
DefaultCacheMonitor m1_again = new DefaultCacheMonitor("l1_monitor_again");
DefaultCacheMonitor m2 = new DefaultCacheMonitor("l2");
DefaultCacheMonitor mc = new DefaultCacheMonitor("mc");
l1Cache = new MonitoredCache(l1Cache, m1);
l1Cache = new MonitoredCache(l1Cache, m1_again);
l2Cache = new MonitoredCache(l2Cache, m2);
cache = new MultiLevelCache<>(l1Cache, l2Cache);
cache = new MonitoredCache<>(cache, mc);
DefaultCacheMonitorManager logger = new DefaultCacheMonitorManager(1, TimeUnit.SECONDS, true);
logger.add(m1, m1_again, m2, mc);
logger.start();
test.run();
logger.stop();
}
use of com.alicp.jetcache.support.DefaultCacheMonitorManager in project jetcache by alibaba.
the class CacheMonitorExample method main.
public static void main(String[] args) throws Exception {
DefaultCacheMonitor orderCacheMonitor = new DefaultCacheMonitor("OrderCache");
Cache<String, Integer> cache = CaffeineCacheBuilder.createCaffeineCacheBuilder().limit(100).expireAfterWrite(200, TimeUnit.SECONDS).keyConvertor(FastjsonKeyConvertor.INSTANCE).addMonitor(orderCacheMonitor).buildCache();
boolean verboseLog = false;
DefaultCacheMonitorManager statLogger = new DefaultCacheMonitorManager(1, TimeUnit.SECONDS, verboseLog);
statLogger.add(orderCacheMonitor);
statLogger.start();
Thread t = new Thread(() -> {
for (int i = 0; i < 100; i++) {
cache.put("20161111", 123456789);
cache.get("20161111");
cache.get("20161212");
cache.remove("20161111");
cache.remove("20161212");
try {
Thread.sleep(100);
} catch (Exception e) {
}
}
});
t.start();
t.join();
statLogger.stop();
}
use of com.alicp.jetcache.support.DefaultCacheMonitorManager in project jetcache by alibaba.
the class CacheContext method init.
@PostConstruct
public synchronized void init() {
if (cacheManager == null) {
this.cacheManager = new CacheManager();
if (globalCacheConfig.getStatIntervalMinutes() > 0) {
defaultCacheMonitorManager = new DefaultCacheMonitorManager(globalCacheConfig.getStatIntervalMinutes(), TimeUnit.MINUTES, globalCacheConfig.getConfigProvider().statCallback());
defaultCacheMonitorManager.start();
}
}
}
use of com.alicp.jetcache.support.DefaultCacheMonitorManager in project jetcache by alibaba.
the class CacheMonitorWithMultiLevelCacheExample method main.
public static void main(String[] args) throws Exception {
DefaultCacheMonitor l1CacheMonitor = new DefaultCacheMonitor("OrderCache_L1");
DefaultCacheMonitor l2CacheMonitor = new DefaultCacheMonitor("OrderCache_L2");
DefaultCacheMonitor orderCacheMonitor = new DefaultCacheMonitor("OrderCache");
Cache<String, Integer> l1Cache = CaffeineCacheBuilder.createCaffeineCacheBuilder().limit(100).expireAfterWrite(200, TimeUnit.SECONDS).keyConvertor(FastjsonKeyConvertor.INSTANCE).addMonitor(l1CacheMonitor).buildCache();
Cache<String, Integer> l2Cache = CaffeineCacheBuilder.createCaffeineCacheBuilder().limit(100).expireAfterWrite(200, TimeUnit.SECONDS).keyConvertor(FastjsonKeyConvertor.INSTANCE).addMonitor(l2CacheMonitor).buildCache();
Cache<String, Integer> orderCache = MultiLevelCacheBuilder.createMultiLevelCacheBuilder().addCache(l1Cache, l2Cache).addMonitor(orderCacheMonitor).buildCache();
boolean verboseLog = true;
DefaultCacheMonitorManager statLogger = new DefaultCacheMonitorManager(1, TimeUnit.SECONDS, verboseLog);
statLogger.add(l1CacheMonitor, l2CacheMonitor, orderCacheMonitor);
statLogger.start();
Thread t = new Thread(() -> {
for (int i = 0; i < 100; i++) {
orderCache.put("20161111", 123456789);
orderCache.get("20161111");
orderCache.get("20161212");
orderCache.remove("20161111");
orderCache.remove("20161212");
orderCache.computeIfAbsent("20161111", (k) -> 100000);
try {
Thread.sleep(100);
} catch (Exception e) {
}
}
});
t.start();
t.join();
statLogger.stop();
}
Aggregations