Added caching.

This commit is contained in:
neviyn 2018-10-10 11:10:07 +01:00
parent 691f585485
commit cbdcd80fef
4 changed files with 17 additions and 1 deletions

View File

@ -56,6 +56,10 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-cache</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.module</groupId>
<artifactId>jackson-module-kotlin</artifactId>
@ -95,6 +99,11 @@
<artifactId>usertype.core</artifactId>
<version>7.0.0.CR1</version>
</dependency>
<dependency>
<groupId>com.github.ben-manes.caffeine</groupId>
<artifactId>caffeine</artifactId>
<version>2.6.2</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>

View File

@ -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<Observation> {
if (observationsRequest.tutor != null) {
return tutorRepository.findById(observationsRequest.tutor).map {

View File

@ -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

View File

@ -2,3 +2,6 @@ spring.jpa.properties.jadira.usertype.autoRegisterUserTypes = true
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.caffeine.spec=maximumSize=500,expireAfterAccess=600s