Search in sources :

Example 1 with ExternalCacheBuilder

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();
}
Also used : ExternalCacheBuilder(com.alicp.jetcache.external.ExternalCacheBuilder) CacheConfigException(com.alicp.jetcache.CacheConfigException)

Example 2 with ExternalCacheBuilder

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)));
}
Also used : ExternalCacheBuilder(com.alicp.jetcache.external.ExternalCacheBuilder)

Aggregations

ExternalCacheBuilder (com.alicp.jetcache.external.ExternalCacheBuilder)2 CacheConfigException (com.alicp.jetcache.CacheConfigException)1