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

Introduce Application Data Caching #24

Merged
merged 2 commits into from
Jun 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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

Loading