This project provides Netflix EVCache integrations for Spring Boot. See on spring-boot-sample
-
Dependency Management
repositories {
jcenter() (1)
}
dependencies {
compile 'com.github.aafwu00:evcache-client-spring-boot-starter:x.y.z' (2)
}
-
add
jcenter()
repository -
add dependency
-
Write java code
-
@SpringBootApplication
@EnableCaching # (1)
public class Application {
public static void main(final String[] args) {
new SpringApplicationBuilder(Application.class).run(args);
}
}
@Repository
public class TodoRepository {
@Cacheable(cacheNames = "todos", key = "'findAll'") # (2)
public List<Todo> findAll() {
return ...;
}
}
-
cacheNames
is sames asevcache.clusters[].appName + . + evcache.clusters[].keyPrefix
, whenevcache.clusters[].name
is blank-
Write
application.yml
code, See on Sample
-
evcache:
clusters:
todos: # (1)
appName: EVCACHE # (2)
keyPrefix: todos # (3)
exception-throwing-enabled: false
EVCACHE-NODES: shard1=localhost:11211,localhost:11212;shard2=localhost:11213,localhost:11214 # (4)
-
Cache Name(same as
@Cacheable
cacheNames
) -
EVCache Cluster App Name
-
EVCache Cache Prefix
-
#{evcache.clusters.todos.appName}
+-NODES
means memcached server address, see on : https://github.com/Netflix/EVCache/wiki/Sample-EVCache-Deployment#step-4-create-a-cache-deployment-descriptor
Important
|
spring.cache.type value is exists, evcache will be ignored
|
Name | Default | Description |
---|---|---|
evcache.enabled |
true |
|
evcache.allowNullValues |
true |
Whether to allow cache for null values |
evcache.deleteWhitespaceKey |
false |
Delete whitespace key. Careful, Both of 'ab' and 'a b' are same key |
evcache.clusters.[cacheName] |
Name of the Cache, @Cacheable cacheName |
|
evcache.clusters.[cacheName].striped |
0 |
The minimum number of stripes (locks) required. default is zero, if zero then striped will be cpu * 4 |
evcache.clusters.[cacheName].appName |
Name of the EVCache App clusters, Recommend Upper Case |
|
evcache.clusters.[cacheName].keyPrefix |
Cache Prefix Key, Don’t contain colon(:) character |
|
evcache.clusters.[cacheName].timeToLive |
900s |
Default Time To Live(TTL), Seconds |
evcache.clusters.[cacheName].retryEnabled |
true |
Retry across Server Group for cache misses and exceptions |
evcache.clusters.[cacheName].exceptionThrowingEnabled |
false |
Exceptions are not propagated and null values are returned |
evcache.metrics.enabled |
true |
Spring Boot Metrics for EVCache |