use of com.alicp.jetcache.RefreshCache in project jetcache by alibaba.
the class CacheContext method buildCache.
protected Cache buildCache(CacheAnnoConfig cacheAnnoConfig, String area, String fullCacheName) {
Cache cache;
if (cacheAnnoConfig.getCacheType() == CacheType.LOCAL) {
cache = buildLocal(cacheAnnoConfig, area);
} else if (cacheAnnoConfig.getCacheType() == CacheType.REMOTE) {
cache = buildRemote(cacheAnnoConfig, area, fullCacheName);
} else {
Cache local = buildLocal(cacheAnnoConfig, area);
Cache remote = buildRemote(cacheAnnoConfig, area, fullCacheName);
if (defaultCacheMonitorManager != null) {
DefaultCacheMonitor localMonitor = new DefaultCacheMonitor(fullCacheName + "_local");
local.config().getMonitors().add(localMonitor);
DefaultCacheMonitor remoteMonitor = new DefaultCacheMonitor(fullCacheName + "_remote");
remote.config().getMonitors().add(remoteMonitor);
defaultCacheMonitorManager.add(localMonitor, remoteMonitor);
}
cache = MultiLevelCacheBuilder.createMultiLevelCacheBuilder().expireAfterWrite(local.config().getExpireAfterWriteInMillis(), TimeUnit.MILLISECONDS).addCache(local, remote).buildCache();
}
cache = new RefreshCache(cache);
if (defaultCacheMonitorManager != null) {
DefaultCacheMonitor monitor = new DefaultCacheMonitor(fullCacheName);
cache.config().getMonitors().add(monitor);
defaultCacheMonitorManager.add(monitor);
}
return cache;
}
Aggregations