From 0fcfcfaa0924a18c978233503051c9e21491280f Mon Sep 17 00:00:00 2001 From: Nathan Cannon Date: Wed, 10 Oct 2018 12:23:04 +0100 Subject: [PATCH] Added caching to chart endpoint. --- .../main/kotlin/uk/co/neviyn/observationdatabase/Controller.kt | 3 ++- backend/src/main/resources/application.properties | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/backend/src/main/kotlin/uk/co/neviyn/observationdatabase/Controller.kt b/backend/src/main/kotlin/uk/co/neviyn/observationdatabase/Controller.kt index 8680608..8c0d6dc 100644 --- a/backend/src/main/kotlin/uk/co/neviyn/observationdatabase/Controller.kt +++ b/backend/src/main/kotlin/uk/co/neviyn/observationdatabase/Controller.kt @@ -119,7 +119,7 @@ class Controller { * Get all observations that are within the constraints provided in [observationsRequest]. */ @PostMapping("/observations") - @Cacheable("observations") + @Cacheable("observations", key = "#observationsRequest") fun getObservations(@Valid @RequestBody observationsRequest: ObservationsRequest): List { if (observationsRequest.tutor != null) { return tutorRepository.findById(observationsRequest.tutor).map { @@ -155,6 +155,7 @@ class Controller { * in a format compatible with ChartJS. */ @PostMapping("/observations/chartdata") + @Cacheable("charts", key = "#observationsRequest") fun getObservationsChartData(@Valid @RequestBody observationsRequest: ObservationsRequest): ChartData? { val data = getObservations(observationsRequest) if (data.isEmpty()) return ChartData(listOf(), listOf()) diff --git a/backend/src/main/resources/application.properties b/backend/src/main/resources/application.properties index 5230070..34c3abb 100644 --- a/backend/src/main/resources/application.properties +++ b/backend/src/main/resources/application.properties @@ -3,5 +3,6 @@ spring.datasource.url=jdbc:h2:file:./database spring.jpa.hibernate.ddl-auto=update obsdb.password=observation spring.cache.type=caffeine -spring.cache.cache-names=observations +spring.cache.cache-names=observations,charts spring.cache.caffeine.spec=maximumSize=500,expireAfterAccess=600s +management.endpoints.web.exposure.include=health,info,metrics \ No newline at end of file