- refactored CacheHelper class (#756)
This commit is contained in:
parent
de1b5e0a17
commit
35009ad3c4
|
@ -1,24 +0,0 @@
|
|||
package org.baeldung.ehcache.app;
|
||||
|
||||
import org.baeldung.ehcache.calculator.SquaredCalculator;
|
||||
import org.baeldung.ehcache.config.CacheHelper;
|
||||
|
||||
public class App {
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
SquaredCalculator squaredCalculator = new SquaredCalculator();
|
||||
CacheHelper cacheHelper = new CacheHelper();
|
||||
|
||||
squaredCalculator.setCache(cacheHelper);
|
||||
|
||||
calculate(squaredCalculator);
|
||||
calculate(squaredCalculator);
|
||||
}
|
||||
|
||||
private static void calculate(SquaredCalculator squaredCalculator) {
|
||||
for (int i = 10; i < 15; i++) {
|
||||
System.out.println("Square value of " + i + " is: " + squaredCalculator.getSquareValueOfNumber(i) + "\n");
|
||||
}
|
||||
}
|
||||
}
|
|
@ -12,14 +12,18 @@ public class CacheHelper {
|
|||
private Cache<Integer, Integer> squareNumberCache;
|
||||
|
||||
public CacheHelper() {
|
||||
cacheManager = CacheManagerBuilder.newCacheManagerBuilder().withCache("squaredNumber", CacheConfigurationBuilder.newCacheConfigurationBuilder(Integer.class, Integer.class, ResourcePoolsBuilder.heap(10))).build();
|
||||
cacheManager = CacheManagerBuilder.newCacheManagerBuilder().build();
|
||||
cacheManager.init();
|
||||
|
||||
squareNumberCache = cacheManager.getCache("squaredNumber", Integer.class, Integer.class);
|
||||
squareNumberCache = cacheManager.createCache("squaredNumber", CacheConfigurationBuilder.newCacheConfigurationBuilder(Integer.class, Integer.class, ResourcePoolsBuilder.heap(10)));
|
||||
}
|
||||
|
||||
public Cache<Integer, Integer> getSquareNumberCache() {
|
||||
return squareNumberCache;
|
||||
}
|
||||
|
||||
public Cache<Integer, Integer> getSquareNumberCacheFromCacheManager() {
|
||||
return cacheManager.getCache("squaredNumber", Integer.class, Integer.class);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue