Skip to content
This repository has been archived by the owner on Jul 26, 2024. It is now read-only.

Commit

Permalink
Merge pull request #24 from ralf-ueberfuhr-ars/feature/application-ca…
Browse files Browse the repository at this point in the history
…ching

Introduce Application Data Caching
  • Loading branch information
ralf-ueberfuhr-ars authored Jun 21, 2024
2 parents eff0d09 + c5dd289 commit dcf5877
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 1 deletion.
8 changes: 8 additions & 0 deletions customer-api-consumer/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,14 @@
<groupId>io.quarkus</groupId>
<artifactId>quarkus-rest-client-reactive-jsonb</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-smallrye-health</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-cache</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-junit5</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import de.schulung.sample.consumer.client.CustomerApi;
import de.schulung.sample.consumer.client.CustomerDto;
import io.quarkus.cache.CacheInvalidateAll;
import io.quarkus.cache.CacheResult;
import io.smallrye.mutiny.Uni;
import jakarta.enterprise.context.ApplicationScoped;
import lombok.RequiredArgsConstructor;
Expand All @@ -14,7 +16,14 @@ public class CustomerService {

private final CustomerApi customerApi;

// https://quarkus.io/guides/cache

@CacheResult(cacheName = "customers-api-cache")
public Uni<Collection<CustomerDto>> getAllCustomers() { // quick'n'dirty without mapping!
return customerApi.getAllCustomers();
}

@CacheInvalidateAll(cacheName = "customers-api-cache")
public void reset(){}

}
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,12 @@ public Uni<String> getCustomerNames() {
);
}

@GET
@Produces(MediaType.TEXT_PLAIN)
@Path("/reset")
public String reset() {
this.service.reset();
return "Done.";
}

}
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
%dev.quarkus.http.port=8081
%dev.quarkus.rest-client."customer-api".url=http://localhost:8080
quarkus.rest-client."customer-api".connect-timeout=2000
%dev.quarkus.rest-client."customer-api".read-timeout=2000
%dev.quarkus.rest-client."customer-api".read-timeout=2000

quarkus.cache.caffeine."customers-api-cache".metrics-enabled=true
quarkus.cache.caffeine."customers-api-cache".expire-after-write=60S
quarkus.management.port=9091
quarkus.management.enabled=true
%dev.quarkus.management.host=localhost

0 comments on commit dcf5877

Please sign in to comment.