use of com.alicp.jetcache.Cache 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;
}
use of com.alicp.jetcache.Cache in project jetcache by alibaba.
the class CacheContext method __createOrGetCache.
public Cache __createOrGetCache(CacheAnnoConfig cacheAnnoConfig, String area, String fullCacheName) {
Cache cache = cacheManager.getCache(fullCacheName);
if (cache == null) {
synchronized (this) {
cache = cacheManager.getCache(fullCacheName);
if (cache == null) {
cache = buildCache(cacheAnnoConfig, area, fullCacheName);
cacheManager.addCache(fullCacheName, cache);
}
}
}
return cache;
}
use of com.alicp.jetcache.Cache in project jetcache by alibaba.
the class CacheContext method buildLocal.
protected Cache buildLocal(CacheAnnoConfig cacheAnnoConfig, String area) {
Cache cache;
EmbeddedCacheBuilder cacheBuilder = (EmbeddedCacheBuilder) globalCacheConfig.getLocalCacheBuilders().get(area);
if (cacheBuilder == null) {
throw new CacheConfigException("no local cache builder: " + area);
}
cacheBuilder = (EmbeddedCacheBuilder) cacheBuilder.clone();
if (cacheAnnoConfig.getLocalLimit() != CacheConsts.UNDEFINED_INT) {
cacheBuilder.setLimit(cacheAnnoConfig.getLocalLimit());
}
if (cacheAnnoConfig.getExpire() > 0) {
cacheBuilder.expireAfterWrite(cacheAnnoConfig.getExpire(), cacheAnnoConfig.getTimeUnit());
}
if (!CacheConsts.UNDEFINED_STRING.equals(cacheAnnoConfig.getKeyConvertor())) {
cacheBuilder.setKeyConvertor(configProvider.parseKeyConvertor(cacheAnnoConfig.getKeyConvertor()));
}
cache = cacheBuilder.buildCache();
return cache;
}
use of com.alicp.jetcache.Cache in project jetcache by alibaba.
the class SimpleCacheManager method getCache.
@Override
public Cache getCache(String area, String cacheName) {
ConcurrentHashMap<String, Cache> areaMap = getCachesByArea(area);
Cache c = areaMap.get(cacheName);
if (c == null && cacheCreator != null) {
return cacheCreator.apply(area, cacheName);
} else {
return c;
}
}
use of com.alicp.jetcache.Cache in project jetcache by alibaba.
the class CacheContext method createCacheByCachedConfig.
private Cache createCacheByCachedConfig(CachedAnnoConfig ac, CacheInvokeContext invokeContext) {
String area = ac.getArea();
String cacheName = ac.getName();
if (CacheConsts.isUndefined(cacheName)) {
cacheName = configProvider.createCacheNameGenerator(invokeContext.getHiddenPackages()).generateCacheName(invokeContext.getMethod(), invokeContext.getTargetObject());
}
Cache cache = __createOrGetCache(ac, area, cacheName);
return cache;
}
Aggregations