@Test public void build() { assertTrue(new SpringCacheBuilder("heap").build() instanceof HeapCache); SpringCacheBuilder builder = new SpringCacheBuilder(); builder.setType("heap"); assertTrue(builder.build() instanceof HeapCache); builder.setType("redis"); builder.setConcurrencyLevel(2); builder.setCacheLoader(key -> null); builder.setEvictionListener((key, value) -> { }); builder.setIndexHandler(new DefaultIndexHandler<>()); builder.setRedisHost("localhost"); builder.setRedisPort(6379); builder.setSerializer(new Serializer<Object>() { @Override public byte[] serialize(Object value) { return value.toString().getBytes(); } @Override public Object deserialize(byte[] payload) { return new String(payload); } }); assertTrue(builder.build() instanceof RedisCache); builder.setType("offheap"); builder.setEvictionPeriod(2); builder.setHeapCapacity(19999); builder.setBufferCleanerPeriod(1000); builder.setBufferCleanerThreshold(0.6F); OffHeapByteBufferStore bufferStore = new OffHeapByteBufferStore(8388608, 2); builder.setBufferStore(bufferStore); assertTrue(builder.build("off-heap") instanceof OffHeapCache); builder.setType("versioned_offheap"); assertTrue(builder.build() instanceof VersionedOffHeapCache); }
public <K, V> Cache<K, V> build() { switch (this.type) { case OFFHEAP: return CacheBuilder.offHeapCache().cacheLoader(cacheLoader) .evictionListener(evictionListener) .indexHandler(indexHandler).concurrencyLevel(concurrencyLevel) .bufferCleanerPeriod(bufferCleanerPeriod).bufferCleanerThreshold(bufferCleanerThreshold) .evictionPeriod(evictionPeriod).serializer(serializer).storage(bufferStore).build(); case VERSIONED_OFFHEAP: return CacheBuilder.versionedOffHeapCache().cacheLoader(cacheLoader) .evictionListener(evictionListener) .indexHandler(indexHandler).concurrencyLevel(concurrencyLevel) .bufferCleanerPeriod(bufferCleanerPeriod).bufferCleanerThreshold(bufferCleanerThreshold) .evictionPeriod(evictionPeriod).serializer(serializer).storage(bufferStore).build(); case REDIS: return CacheBuilder.redisCache().cacheLoader(cacheLoader).evictionListener(evictionListener) .serializer(serializer).concurrencyLevel(concurrencyLevel).hostName(redisHost) .port(redisPort) .build(); default: return CacheBuilder.heapCache().cacheLoader(cacheLoader).evictionListener(evictionListener) .indexHandler(indexHandler).build(); } }
SpringCacheBuilder extends BaseCacheBuilder { public <K, V> Cache<K, V> build() { switch (this.type) { case OFFHEAP: return CacheBuilder.offHeapCache().cacheLoader(cacheLoader) .evictionListener(evictionListener) .indexHandler(indexHandler).concurrencyLevel(concurrencyLevel) .bufferCleanerPeriod(bufferCleanerPeriod).bufferCleanerThreshold(bufferCleanerThreshold) .evictionPeriod(evictionPeriod).serializer(serializer).storage(bufferStore).build(); case VERSIONED_OFFHEAP: return CacheBuilder.versionedOffHeapCache().cacheLoader(cacheLoader) .evictionListener(evictionListener) .indexHandler(indexHandler).concurrencyLevel(concurrencyLevel) .bufferCleanerPeriod(bufferCleanerPeriod).bufferCleanerThreshold(bufferCleanerThreshold) .evictionPeriod(evictionPeriod).serializer(serializer).storage(bufferStore).build(); case REDIS: return CacheBuilder.redisCache().cacheLoader(cacheLoader).evictionListener(evictionListener) .serializer(serializer).concurrencyLevel(concurrencyLevel).hostName(redisHost) .port(redisPort) .build(); default: return CacheBuilder.heapCache().cacheLoader(cacheLoader).evictionListener(evictionListener) .indexHandler(indexHandler).build(); } } }
SpringCacheBuilder extends BaseCacheBuilder { public <K, V> Cache<K, V> build() { switch (this.type) { case OFFHEAP: return CacheBuilder.offHeapCache().cacheLoader(cacheLoader) .evictionListener(evictionListener) .indexHandler(indexHandler).concurrencyLevel(concurrencyLevel) .bufferCleanerPeriod(bufferCleanerPeriod).bufferCleanerThreshold(bufferCleanerThreshold) .evictionPeriod(evictionPeriod).serializer(serializer).storage(bufferStore).build(); case VERSIONED_OFFHEAP: return CacheBuilder.versionedOffHeapCache().cacheLoader(cacheLoader) .evictionListener(evictionListener) .indexHandler(indexHandler).concurrencyLevel(concurrencyLevel) .bufferCleanerPeriod(bufferCleanerPeriod).bufferCleanerThreshold(bufferCleanerThreshold) .evictionPeriod(evictionPeriod).serializer(serializer).storage(bufferStore).build(); case REDIS: return CacheBuilder.redisCache().cacheLoader(cacheLoader).evictionListener(evictionListener) .serializer(serializer).concurrencyLevel(concurrencyLevel).hostName(redisHost) .port(redisPort) .build(); default: return CacheBuilder.heapCache().cacheLoader(cacheLoader).evictionListener(evictionListener) .indexHandler(indexHandler).build(); } } SpringCacheBuilder();  SpringCacheBuilder(String type); }
SpringCacheBuilder extends BaseCacheBuilder { public <K, V> Cache<K, V> build() { switch (this.type) { case OFFHEAP: return CacheBuilder.offHeapCache().cacheLoader(cacheLoader) .evictionListener(evictionListener) .indexHandler(indexHandler).concurrencyLevel(concurrencyLevel) .bufferCleanerPeriod(bufferCleanerPeriod).bufferCleanerThreshold(bufferCleanerThreshold) .evictionPeriod(evictionPeriod).serializer(serializer).storage(bufferStore).build(); case VERSIONED_OFFHEAP: return CacheBuilder.versionedOffHeapCache().cacheLoader(cacheLoader) .evictionListener(evictionListener) .indexHandler(indexHandler).concurrencyLevel(concurrencyLevel) .bufferCleanerPeriod(bufferCleanerPeriod).bufferCleanerThreshold(bufferCleanerThreshold) .evictionPeriod(evictionPeriod).serializer(serializer).storage(bufferStore).build(); case REDIS: return CacheBuilder.redisCache().cacheLoader(cacheLoader).evictionListener(evictionListener) .serializer(serializer).concurrencyLevel(concurrencyLevel).hostName(redisHost) .port(redisPort) .build(); default: return CacheBuilder.heapCache().cacheLoader(cacheLoader).evictionListener(evictionListener) .indexHandler(indexHandler).build(); } } SpringCacheBuilder();  SpringCacheBuilder(String type); Cache<K, V> build(); Cache<K, V> build(final String name); void setType(String type); void setConcurrencyLevel(int concurrencyLevel); void setEvictionPeriod(long evictionPeriod); void setBufferCleanerPeriod(long bufferCleanerPeriod); void setBufferCleanerThreshold(float bufferCleanerThreshold); void setSerializer(Serializer<Object> serializer); void setCacheLoader(CacheLoader<Object, Object> cacheLoader); void setEvictionListener(EvictionListener<Object, Object> evictionListener); void setIndexHandler(IndexHandler<Object, Object> indexHandler); void setBufferStore(OffHeapByteBufferStore bufferStore); void setRedisHost(String redisHost); void setRedisPort(int redisPort); void setHeapCapacity(int heapCapacity); }
SpringCacheBuilder extends BaseCacheBuilder { public <K, V> Cache<K, V> build() { switch (this.type) { case OFFHEAP: return CacheBuilder.offHeapCache().cacheLoader(cacheLoader) .evictionListener(evictionListener) .indexHandler(indexHandler).concurrencyLevel(concurrencyLevel) .bufferCleanerPeriod(bufferCleanerPeriod).bufferCleanerThreshold(bufferCleanerThreshold) .evictionPeriod(evictionPeriod).serializer(serializer).storage(bufferStore).build(); case VERSIONED_OFFHEAP: return CacheBuilder.versionedOffHeapCache().cacheLoader(cacheLoader) .evictionListener(evictionListener) .indexHandler(indexHandler).concurrencyLevel(concurrencyLevel) .bufferCleanerPeriod(bufferCleanerPeriod).bufferCleanerThreshold(bufferCleanerThreshold) .evictionPeriod(evictionPeriod).serializer(serializer).storage(bufferStore).build(); case REDIS: return CacheBuilder.redisCache().cacheLoader(cacheLoader).evictionListener(evictionListener) .serializer(serializer).concurrencyLevel(concurrencyLevel).hostName(redisHost) .port(redisPort) .build(); default: return CacheBuilder.heapCache().cacheLoader(cacheLoader).evictionListener(evictionListener) .indexHandler(indexHandler).build(); } } SpringCacheBuilder();  SpringCacheBuilder(String type); Cache<K, V> build(); Cache<K, V> build(final String name); void setType(String type); void setConcurrencyLevel(int concurrencyLevel); void setEvictionPeriod(long evictionPeriod); void setBufferCleanerPeriod(long bufferCleanerPeriod); void setBufferCleanerThreshold(float bufferCleanerThreshold); void setSerializer(Serializer<Object> serializer); void setCacheLoader(CacheLoader<Object, Object> cacheLoader); void setEvictionListener(EvictionListener<Object, Object> evictionListener); void setIndexHandler(IndexHandler<Object, Object> indexHandler); void setBufferStore(OffHeapByteBufferStore bufferStore); void setRedisHost(String redisHost); void setRedisPort(int redisPort); void setHeapCapacity(int heapCapacity);  }