petclinic-memoizeit

added memoizeit cache

6/29/2019 5:57:01 AM

Details

diff --git a/docker-compose.yml b/docker-compose.yml
index cdcd084..602fd6f 100644
--- a/docker-compose.yml
+++ b/docker-compose.yml
@@ -10,12 +10,8 @@ services:
     command: bash -c 'while !</dev/tcp/database/3306; do sleep 5; done; bash run.sh'
     environment:
       - JAVA_OPTS=${JAVA_OPTS:-"-Xms4096m -Xmx6124m"}
-      - TRACER_ENABLE=${TRACER_ENABLE:-true}
-      - TRACER_MINIMUM_EXECUTION_TIME=${TRACER_MINIMUM_EXECUTION_TIME:-1}
-      - TRACER_SERIALISE_INTERNALS=false
-      - TRACER_VERBOSE=true
-      - TRACER_TRACES=/caching-approaches-comparison/applications/traces/petclinic
-      - TRACER_LOG=/caching-approaches-comparison/applications/output/petclinic-tracer.log
+      - CACHE_EVENTS=${CACHE_EVENTS:-/caching-approaches-comparison/applications/output/petclinic-memoizeit-cache}
+      - CACHE_REGISTER_SIZE=false
     volumes:
       - application:/application
       - /root/.m2:/root/.m2

pom.xml 51(+2 -49)

diff --git a/pom.xml b/pom.xml
index ca29161..cc6dcae 100644
--- a/pom.xml
+++ b/pom.xml
@@ -117,8 +117,8 @@
     </dependency>
 
         <dependency>
-            <groupId>br.ufrgs.inf.prosoft.applicationtracer</groupId>
-            <artifactId>ApplicationTracer</artifactId>
+            <groupId>br.ufrgs.inf.prosoft.cache</groupId>
+            <artifactId>Cache</artifactId>
             <version>1.0</version>
         </dependency>
 
@@ -126,53 +126,6 @@
 
   <build>
     <plugins>
-
-            <plugin>
-                <groupId>org.codehaus.mojo</groupId>
-                <artifactId>aspectj-maven-plugin</artifactId>
-                <version>1.11</version>
-                <configuration>
-                    <showWeaveInfo>false</showWeaveInfo>
-                    <complianceLevel>1.8</complianceLevel>
-                    <source>1.6</source>
-                    <target>1.6</target>
-                    <Xlint>ignore</Xlint>
-                    <encoding>UTF-8</encoding>
-                    <verbose>false</verbose>
-                    <forceAjcCompile>true</forceAjcCompile>
-                    <sources/>
-                    <weaveDirectories>
-                        <weaveDirectory>${project.build.directory}/classes</weaveDirectory>
-                    </weaveDirectories>
-                    <aspectLibraries>
-                        <aspectLibrary>
-                            <groupId>br.ufrgs.inf.prosoft.applicationtracer</groupId>
-                            <artifactId>ApplicationTracer</artifactId>
-                        </aspectLibrary>
-                    </aspectLibraries>
-                </configuration>
-                <executions>
-                    <execution>
-                        <phase>process-classes</phase>
-                        <goals>
-                            <goal>compile</goal>
-                        </goals>
-                    </execution>
-                </executions>
-                <dependencies>
-                    <dependency>
-                        <groupId>org.aspectj</groupId>
-                        <artifactId>aspectjrt</artifactId>
-                        <version>1.9.1</version>
-                    </dependency>
-                    <dependency>
-                        <groupId>org.aspectj</groupId>
-                        <artifactId>aspectjtools</artifactId>
-                        <version>1.9.1</version>
-                    </dependency>
-                </dependencies>
-            </plugin>
-
       <plugin>
         <groupId>org.springframework.boot</groupId>
         <artifactId>spring-boot-maven-plugin</artifactId>
diff --git a/src/main/java/org/petclinic/vet/VetController.java b/src/main/java/org/petclinic/vet/VetController.java
index dd248cf..76f6a78 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,18 +45,27 @@ 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";
     }
 
-    @GetMapping({ "/vets.json", "/vets.xml" })
-    public @ResponseBody Vets showResourcesVetList() {
+    public static GetterCache<Vets> showResourcesVetListCache = new GetterCache<>("showResourcesVetListCache");
+
+    @GetMapping({"/vets.json", "/vets.xml"})
+    public @ResponseBody
+    Vets showResourcesVetList() {
         // 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());
-        return vets;
+        return showResourcesVetListCache.computeIfAbsent(() -> {
+            Vets vets = new Vets();
+            vets.getVetList().addAll(findAll());
+            return vets;
+        }, 60000);
+    }
+
+    private Collection<Vet> findAll() {
+        return this.vets.findAll();
     }
 
 }