Skip to content

Latest commit

 

History

History
58 lines (51 loc) · 2.19 KB

File metadata and controls

58 lines (51 loc) · 2.19 KB

evcache-client-spring

This project provides Netflix EVCache integrations for Spring Cache Abstraction. See on spring-sample

  1. Dependency Management

repositories {
    jcenter() (1)
}

dependencies {
    compile 'com.github.aafwu00:evcache-client-spring:x.y.z' (2)
}
  1. add jcenter() repository

  2. add dependency

    1. Write java source code

@Configuration
@ComponentScan
@EnableCaching
public class TodoApp {
    @Bean
    public CacheManager cacheManager() {
        final EVCacheConfig config = EVCacheConfig.getInstance();
        config.getPropertyRepository()
              .get("TODO-NODES", String.class)
              .orElseGet("shard1=localhost:11211,localhost:11212;shard2=localhost:11213,localhost:11214"); # (2)
        final EVCacheClientPoolManager evcacheClientPoolManager = new EVCacheClientPoolManager(new ConnectionFactoryBuilder(),
                                                                                               new SimpleNodeListProvider(),
                                                                                               config);
        final EVCacheClientPoolConfigurationProperties properties = new EVCacheClientPoolConfigurationProperties();
        properties.setKeyPrefix("todo");
        properties.setTimeToLive(Duration.ofSeconds(10));
        properties.setRetryEnabled(true);
        properties.setExceptionThrowingEnabled(false);
        final EVCacheConfiguration configuration = new EVCacheConfiguration("todos", 1, "TODO", properties); # (1)
        return new EVCacheManager(evcacheClientPoolManager, Collections.singleton(configuration), Collections.emptyList());
    }
}

@Repository
public class TodoRepository {
    @Cacheable(cacheNames = "todos", key = "'findAll'") # (3)
    public List<Todo> findAll() {
        return ...;
    }
}
  1. EVCacheManager app name is TODO, cache name is todos

  2. EVCacheManager app name + -NODES means memcached server address, see on : https://github.com/Netflix/EVCache/wiki/Sample-EVCache-Deployment#step-4-create-a-cache-deployment-descriptor

  3. cacheNames is sames as configuration cacheName. key must not be contain whitespace.