petclinic-developers

added developers cache

5/26/2019 12:26:04 AM

Details

docker-compose.yml 12(+6 -6)

diff --git a/docker-compose.yml b/docker-compose.yml
index 64ac9da..bd20108 100644
--- a/docker-compose.yml
+++ b/docker-compose.yml
@@ -7,16 +7,16 @@ services:
     - "database"
     links:
       - database
+    command: bash -c 'while !</dev/tcp/database/3306; do sleep 5; done; bash run.sh'
     environment:
       - JAVA_OPTS="-Xms4096m -Xmx6124m"
-      - TRACER_SERIALISE_INTERNALS=false
-      - TRACER_VERBOSE=true
-      - TRACER_ENABLE=true
-      - TRACER_TRACES=/caching-approaches-comparison/applications/traces/petclinic
+      - TRACER_ENABLE=false
+      - CACHE_EVENTS=${CACHE_EVENTS:-/caching-approaches-comparison/applications/output/petclinic-developers-cache}
+      - CACHE_REGISTER_SIZE=false
     volumes:
       - application:/application
       - /root/.m2:/root/.m2
-      - ../../../:/caching-approaches-comparison
+      - ../../../../:/caching-approaches-comparison
     restart: unless-stopped
     ports:
       - 8080:8080
@@ -30,7 +30,7 @@ services:
     expose:
       - 3306
     volumes:
-      - ../../dumps/petclinic.sql:/docker-entrypoint-initdb.d/init.sql
+      - ../../../dumps/petclinic.sql:/docker-entrypoint-initdb.d/init.sql
       - database:/var/lib/mysql
     environment:
       MYSQL_USER: root

pom.xml 6(+6 -0)

diff --git a/pom.xml b/pom.xml
index ca29161..9f13666 100644
--- a/pom.xml
+++ b/pom.xml
@@ -122,6 +122,12 @@
             <version>1.0</version>
         </dependency>
 
+        <dependency>
+            <groupId>br.ufrgs.inf.prosoft.cache</groupId>
+            <artifactId>Cache</artifactId>
+            <version>1.0</version>
+        </dependency>
+
   </dependencies>
 
   <build>
diff --git a/src/main/java/org/petclinic/vet/VetController.java b/src/main/java/org/petclinic/vet/VetController.java
index dd248cf..6a7b103 100644
--- a/src/main/java/org/petclinic/vet/VetController.java
+++ b/src/main/java/org/petclinic/vet/VetController.java
@@ -15,6 +15,8 @@
  */
 package org.petclinic.vet;
 
+import br.ufrgs.inf.prosoft.cache.GetterCache;
+import java.util.Collection;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Controller;
 import org.springframework.web.bind.annotation.GetMapping;
@@ -43,7 +45,7 @@ class VetController {
         // Here we are returning an object of type 'Vets' rather than a collection of Vet
         // objects so it is simpler for Object-Xml mapping
         Vets vets = new Vets();
-        vets.getVetList().addAll(this.vets.findAll());
+        vets.getVetList().addAll(findAll());
         model.put("vets", vets);
         return "vets/vetList";
     }
@@ -53,8 +55,15 @@ class VetController {
         // Here we are returning an object of type 'Vets' rather than a collection of Vet
         // objects so it is simpler for JSon/Object mapping
         Vets vets = new Vets();
-        vets.getVetList().addAll(this.vets.findAll());
+        vets.getVetList().addAll(findAll());
         return vets;
     }
 
+    public static GetterCache<Collection<Vet>> findAllCache = new GetterCache<>("findAllCache");
+    private Collection<Vet> findAll(){
+        return findAllCache.computeIfAbsent(() -> {
+            return this.vets.findAll();
+        }, 60000);
+    }
+
 }