diff --git a/backend/pom.xml b/backend/pom.xml
index 76f041d..b457177 100644
--- a/backend/pom.xml
+++ b/backend/pom.xml
@@ -56,6 +56,10 @@
org.springframework.boot
spring-boot-starter-security
+
+ org.springframework.boot
+ spring-boot-starter-cache
+
com.fasterxml.jackson.module
jackson-module-kotlin
@@ -95,6 +99,11 @@
usertype.core
7.0.0.CR1
+
+ com.github.ben-manes.caffeine
+ caffeine
+ 2.6.2
+
org.springframework.boot
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 108adac..8680608 100644
--- a/backend/src/main/kotlin/uk/co/neviyn/observationdatabase/Controller.kt
+++ b/backend/src/main/kotlin/uk/co/neviyn/observationdatabase/Controller.kt
@@ -2,6 +2,7 @@ package uk.co.neviyn.observationdatabase
import org.joda.time.LocalDate
import org.springframework.beans.factory.annotation.Autowired
+import org.springframework.cache.annotation.Cacheable
import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.PathVariable
import org.springframework.web.bind.annotation.PostMapping
@@ -118,6 +119,7 @@ class Controller {
* Get all observations that are within the constraints provided in [observationsRequest].
*/
@PostMapping("/observations")
+ @Cacheable("observations")
fun getObservations(@Valid @RequestBody observationsRequest: ObservationsRequest): List {
if (observationsRequest.tutor != null) {
return tutorRepository.findById(observationsRequest.tutor).map {
diff --git a/backend/src/main/kotlin/uk/co/neviyn/observationdatabase/ObservationDatabaseApplication.kt b/backend/src/main/kotlin/uk/co/neviyn/observationdatabase/ObservationDatabaseApplication.kt
index 3221559..5d22124 100644
--- a/backend/src/main/kotlin/uk/co/neviyn/observationdatabase/ObservationDatabaseApplication.kt
+++ b/backend/src/main/kotlin/uk/co/neviyn/observationdatabase/ObservationDatabaseApplication.kt
@@ -2,8 +2,10 @@ package uk.co.neviyn.observationdatabase
import org.springframework.boot.autoconfigure.SpringBootApplication
import org.springframework.boot.runApplication
+import org.springframework.cache.annotation.EnableCaching
@SpringBootApplication
+@EnableCaching
class ObservationDatabaseApplication {
companion object {
@JvmStatic
diff --git a/backend/src/main/resources/application.properties b/backend/src/main/resources/application.properties
index fe8bbb9..5230070 100644
--- a/backend/src/main/resources/application.properties
+++ b/backend/src/main/resources/application.properties
@@ -1,4 +1,7 @@
spring.jpa.properties.jadira.usertype.autoRegisterUserTypes = true
spring.datasource.url=jdbc:h2:file:./database
spring.jpa.hibernate.ddl-auto=update
-obsdb.password=observation
\ No newline at end of file
+obsdb.password=observation
+spring.cache.type=caffeine
+spring.cache.cache-names=observations
+spring.cache.caffeine.spec=maximumSize=500,expireAfterAccess=600s