use of com.alicp.jetcache.external.ExternalCacheBuilder in project jetcache by alibaba.
the class CacheContext method buildRemote.
protected Cache buildRemote(CacheAnnoConfig cacheAnnoConfig, String area, String cacheName) {
ExternalCacheBuilder cacheBuilder = (ExternalCacheBuilder) globalCacheConfig.getRemoteCacheBuilders().get(area);
if (cacheBuilder == null) {
throw new CacheConfigException("no remote cache builder: " + area);
}
cacheBuilder = (ExternalCacheBuilder) cacheBuilder.clone();
if (cacheAnnoConfig.getExpire() > 0) {
cacheBuilder.expireAfterWrite(cacheAnnoConfig.getExpire(), cacheAnnoConfig.getTimeUnit());
}
if (cacheBuilder.getConfig().getKeyPrefix() != null) {
cacheBuilder.setKeyPrefix(cacheBuilder.getConfig().getKeyPrefix() + cacheName);
} else {
cacheBuilder.setKeyPrefix(cacheName);
}
if (!CacheConsts.UNDEFINED_STRING.equals(cacheAnnoConfig.getKeyConvertor())) {
cacheBuilder.setKeyConvertor(configProvider.parseKeyConvertor(cacheAnnoConfig.getKeyConvertor()));
}
if (!CacheConsts.UNDEFINED_STRING.equals(cacheAnnoConfig.getSerialPolicy())) {
cacheBuilder.setValueEncoder(configProvider.parseValueEncoder(cacheAnnoConfig.getSerialPolicy()));
cacheBuilder.setValueDecoder(configProvider.parseValueDecoder(cacheAnnoConfig.getSerialPolicy()));
}
return cacheBuilder.buildCache();
}
use of com.alicp.jetcache.external.ExternalCacheBuilder in project jetcache by alibaba.
the class ExternalCacheAutoInit method parseGeneralConfig.
@Override
protected void parseGeneralConfig(CacheBuilder builder, RelaxedPropertyResolver resolver) {
super.parseGeneralConfig(builder, resolver);
ExternalCacheBuilder ecb = (ExternalCacheBuilder) builder;
ecb.setKeyPrefix(resolver.getProperty("keyPrefix"));
ecb.setValueEncoder(configProvider.parseValueEncoder(resolver.getProperty("valueEncoder", CacheConsts.DEFAULT_SERIAL_POLICY)));
ecb.setValueDecoder(configProvider.parseValueDecoder(resolver.getProperty("valueDecoder", CacheConsts.DEFAULT_SERIAL_POLICY)));
}
Aggregations