Search in sources :

Example 1 with EmbeddedCacheBuilder

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;
}
Also used : EmbeddedCacheBuilder(com.alicp.jetcache.embedded.EmbeddedCacheBuilder) CacheConfigException(com.alicp.jetcache.CacheConfigException) RefreshCache(com.alicp.jetcache.RefreshCache) Cache(com.alicp.jetcache.Cache) EnableCache(com.alicp.jetcache.anno.EnableCache)

Example 2 with EmbeddedCacheBuilder

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;
}
Also used : EmbeddedCacheBuilder(com.alicp.jetcache.embedded.EmbeddedCacheBuilder) GlobalCacheConfig(com.alicp.jetcache.anno.support.GlobalCacheConfig) HashMap(java.util.HashMap) Map(java.util.Map) HashMap(java.util.HashMap)

Example 3 with EmbeddedCacheBuilder

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

Aggregations

EmbeddedCacheBuilder (com.alicp.jetcache.embedded.EmbeddedCacheBuilder)3 Cache (com.alicp.jetcache.Cache)1 CacheConfigException (com.alicp.jetcache.CacheConfigException)1 RefreshCache (com.alicp.jetcache.RefreshCache)1 EnableCache (com.alicp.jetcache.anno.EnableCache)1 GlobalCacheConfig (com.alicp.jetcache.anno.support.GlobalCacheConfig)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1