use of com.alicp.jetcache.embedded.EmbeddedCacheBuilder 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.embedded.EmbeddedCacheBuilder in project jetcache by alibaba.
the class TestUtil method createGloableConfig.
public static GlobalCacheConfig createGloableConfig(ConfigProvider configProvider) {
Map localBuilders = new HashMap();
EmbeddedCacheBuilder localBuilder = LinkedHashMapCacheBuilder.createLinkedHashMapCacheBuilder();
// localBuilder.setKeyConvertor(FastjsonKeyConvertor.INSTANCE);
localBuilders.put(CacheConsts.DEFAULT_AREA, localBuilder);
localBuilders.put("A1", localBuilder);
Map remoteBuilders = new HashMap();
MockRemoteCacheBuilder remoteBuilder = new MockRemoteCacheBuilder();
remoteBuilder.setKeyConvertor(FastjsonKeyConvertor.INSTANCE);
remoteBuilder.setValueEncoder(KryoValueEncoder.INSTANCE);
remoteBuilder.setValueDecoder(KryoValueDecoder.INSTANCE);
remoteBuilders.put(CacheConsts.DEFAULT_AREA, remoteBuilder);
remoteBuilder = new MockRemoteCacheBuilder();
// remoteBuilder.setKeyConvertor(FastjsonKeyConvertor.INSTANCE);
remoteBuilder.setValueEncoder(KryoValueEncoder.INSTANCE);
remoteBuilder.setValueDecoder(KryoValueDecoder.INSTANCE);
remoteBuilders.put("A1", remoteBuilder);
GlobalCacheConfig globalCacheConfig = new GlobalCacheConfig();
globalCacheConfig.setConfigProvider(configProvider);
globalCacheConfig.setLocalCacheBuilders(localBuilders);
globalCacheConfig.setRemoteCacheBuilders(remoteBuilders);
// globalCacheConfig.init();
return globalCacheConfig;
}
use of com.alicp.jetcache.embedded.EmbeddedCacheBuilder in project jetcache by alibaba.
the class EmbeddedCacheAutoInit method parseGeneralConfig.
@Override
protected void parseGeneralConfig(CacheBuilder builder, RelaxedPropertyResolver resolver) {
super.parseGeneralConfig(builder, resolver);
EmbeddedCacheBuilder ecb = (EmbeddedCacheBuilder) builder;
ecb.limit(Integer.parseInt(resolver.getProperty("limit", String.valueOf(CacheConsts.DEFAULT_LOCAL_LIMIT))));
}
Aggregations