Browse Source

[fi fw-only Java/servlet] cache2k update (#4091)

* Update cache2k to 1.2.0

* Fix artifactId

* Use IntCache and peek() method to retrieve data from cache
Radoslav Petrov 7 years ago
parent
commit
3972452083

+ 3 - 9
frameworks/Java/servlet/pom.xml

@@ -11,7 +11,7 @@
 	<properties>
 		<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
 		<java-version>1.8</java-version>
-		<cache2k-version>1.0.2.Final</cache2k-version>
+		<cache2k-version>1.2.0.Final</cache2k-version>
 		<jackson-version>2.9.7</jackson-version>
 		<!-- This is the default web.xml for plaintext and json only -->
 		<maven.war.xml>src/main/webapp/WEB-INF/web.xml</maven.war.xml>
@@ -56,15 +56,9 @@
 		<!-- cache2k -->
 		<dependency>
 			<groupId>org.cache2k</groupId>
-			<artifactId>cache2k-api</artifactId>
+			<artifactId>cache2k-base-bom</artifactId>
 			<version>${cache2k-version}</version>
-			<scope>provided</scope>
-		</dependency>
-		<dependency>
-			<groupId>org.cache2k</groupId>
-			<artifactId>cache2k-all</artifactId>
-			<version>${cache2k-version}</version>
-			<scope>runtime</scope>
+			<type>pom</type>	
 		</dependency>
 	</dependencies>
 

+ 4 - 3
frameworks/Java/servlet/src/main/java/hello/Cache2kPostgresServlet.java

@@ -15,6 +15,7 @@ import javax.sql.DataSource;
 
 import org.cache2k.Cache;
 import org.cache2k.Cache2kBuilder;
+import org.cache2k.IntCache;
 
 /**
  * Cache
@@ -27,7 +28,7 @@ public class Cache2kPostgresServlet extends HttpServlet {
 	// Database connection pool.
 	@Resource(name = "jdbc/hello_world")
 	private DataSource dataSource;
-	private Cache<Integer, CachedWorld> cache;
+	private IntCache<CachedWorld> cache;
 
 	@Override
 	public void init(ServletConfig config) throws ServletException {
@@ -42,7 +43,7 @@ public class Cache2kPostgresServlet extends HttpServlet {
 
 		// Build the cache
 		cache = new Cache2kBuilder<Integer, CachedWorld>() {
-		}.name("cachedWorld").eternal(true).entryCapacity(DB_ROWS).build();
+		}.name("cachedWorld").eternal(true).entryCapacity(DB_ROWS).buildForIntKey();
 		cache.putAll(worlds);
 	}
 
@@ -53,7 +54,7 @@ public class Cache2kPostgresServlet extends HttpServlet {
 		final CachedWorld[] worlds = new CachedWorld[count];
 
 		for (int i = 0; i < count; i++) {
-			worlds[i] = cache.get(ThreadLocalRandom.current().nextInt(DB_ROWS) + 1);
+			worlds[i] = cache.peek(ThreadLocalRandom.current().nextInt(DB_ROWS) + 1);
 		}
 
 		// Set content type to JSON