This project provides Netflix EVCache integrations for Spring Cache Abstraction. See on spring-sample
-
Dependency Management
repositories {
jcenter() (1)
}
dependencies {
compile 'com.github.aafwu00:evcache-client-spring:x.y.z' (2)
}
-
add
jcenter()
repository -
add dependency
-
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 ...;
}
}
-
EVCacheManager
app name isTODO
, cache name istodos
-
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 -
cacheNames
is sames as configurationcacheName
.key
must not be contain whitespace.