Refactor Infinispan example (#3684)
* Refactor Infinispan examples * Refactor Infinispan examples
This commit is contained in:
committed by
Predrag Maric
parent
6da6722ec4
commit
c0bf1c7a93
@@ -20,8 +20,7 @@ public class CacheConfiguration {
|
||||
public static final String TRANSACTIONAL_CACHE = "transactional-cache";
|
||||
|
||||
public DefaultCacheManager cacheManager() {
|
||||
DefaultCacheManager cacheManager = new DefaultCacheManager();
|
||||
return cacheManager;
|
||||
return new DefaultCacheManager();
|
||||
}
|
||||
|
||||
public Cache<String, Integer> transactionalCache(DefaultCacheManager cacheManager, CacheListener listener) {
|
||||
|
||||
@@ -40,9 +40,7 @@ public class CacheListener {
|
||||
@CacheEntriesEvicted
|
||||
public void entriesEvicted(CacheEntriesEvictedEvent<String, String> event) {
|
||||
final StringBuilder builder = new StringBuilder();
|
||||
event.getEntries().entrySet().forEach((e) ->
|
||||
builder.append(e.getKey() + ", ")
|
||||
);
|
||||
event.getEntries().forEach((key, value) -> builder.append(key).append(", "));
|
||||
System.out.println("Evicting following entries from cache: " + builder.toString());
|
||||
}
|
||||
|
||||
|
||||
@@ -31,12 +31,7 @@ public class HelloWorldService {
|
||||
|
||||
public String findSimpleHelloWorld() {
|
||||
String cacheKey = "simple-hello";
|
||||
String helloWorld = simpleHelloWorldCache.get(cacheKey);
|
||||
if (helloWorld == null) {
|
||||
helloWorld = repository.getHelloWorld();
|
||||
simpleHelloWorldCache.put(cacheKey, helloWorld);
|
||||
}
|
||||
return helloWorld;
|
||||
return simpleHelloWorldCache.computeIfAbsent(cacheKey, k -> repository.getHelloWorld());
|
||||
}
|
||||
|
||||
public String findExpiringHelloWorld() {
|
||||
@@ -79,12 +74,7 @@ public class HelloWorldService {
|
||||
}
|
||||
|
||||
public String findPassivatingHelloWorld(String key) {
|
||||
String value = passivatingHelloWorldCache.get(key);
|
||||
if(value == null) {
|
||||
value = repository.getHelloWorld();
|
||||
passivatingHelloWorldCache.put(key, value);
|
||||
}
|
||||
return value;
|
||||
return passivatingHelloWorldCache.computeIfAbsent(key, k -> repository.getHelloWorld());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user