use of com.alicp.jetcache.Cache in project jetcache by alibaba.
the class CacheContext method buildCache.
protected Cache buildCache(CachedAnnoConfig cachedAnnoConfig, String area, String cacheName) {
Cache cache;
if (cachedAnnoConfig.getCacheType() == CacheType.LOCAL) {
cache = buildLocal(cachedAnnoConfig, area);
} else if (cachedAnnoConfig.getCacheType() == CacheType.REMOTE) {
cache = buildRemote(cachedAnnoConfig, area, cacheName);
} else {
Cache local = buildLocal(cachedAnnoConfig, area);
Cache remote = buildRemote(cachedAnnoConfig, area, cacheName);
boolean useExpireOfSubCache = cachedAnnoConfig.getLocalExpire() > 0;
cache = MultiLevelCacheBuilder.createMultiLevelCacheBuilder().expireAfterWrite(remote.config().getExpireAfterWriteInMillis(), TimeUnit.MILLISECONDS).addCache(local, remote).useExpireOfSubCache(useExpireOfSubCache).cacheNullValue(cachedAnnoConfig.isCacheNullValue()).buildCache();
}
cache.config().setRefreshPolicy(cachedAnnoConfig.getRefreshPolicy());
cache = new CacheHandler.CacheHandlerRefreshCache(cache);
cache.config().setCachePenetrationProtect(globalCacheConfig.isPenetrationProtect());
PenetrationProtectConfig protectConfig = cachedAnnoConfig.getPenetrationProtectConfig();
if (protectConfig != null) {
cache.config().setCachePenetrationProtect(protectConfig.isPenetrationProtect());
cache.config().setPenetrationProtectTimeout(protectConfig.getPenetrationProtectTimeout());
}
if (configProvider.getCacheMonitorManager() != null) {
configProvider.getCacheMonitorManager().addMonitors(area, cacheName, cache);
}
return cache;
}
use of com.alicp.jetcache.Cache in project jetcache by alibaba.
the class CacheContext method __createOrGetCache.
public Cache __createOrGetCache(CachedAnnoConfig cachedAnnoConfig, String area, String cacheName) {
String fullCacheName = area + "_" + cacheName;
Cache cache = cacheManager.getCacheWithoutCreate(area, cacheName);
if (cache == null) {
synchronized (this) {
cache = cacheManager.getCacheWithoutCreate(area, cacheName);
if (cache == null) {
if (globalCacheConfig.isAreaInCacheName()) {
// for compatible reason, if we use default configuration, the prefix should same to that version <=2.4.3
cache = buildCache(cachedAnnoConfig, area, fullCacheName);
} else {
cache = buildCache(cachedAnnoConfig, area, cacheName);
}
cacheManager.putCache(area, cacheName, cache);
}
}
}
return cache;
}
Aggregations