Skip to content

Commit a14c655

Browse files
author
akuksin
committed
add custom key for caching
1 parent 6b66a6e commit a14c655

1 file changed

Lines changed: 3 additions & 3 deletions

File tree

  • spring-boot/cache/src/main/java/io/reflectoring/cache/service

spring-boot/cache/src/main/java/io/reflectoring/cache/service/CarService.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,12 @@ public Car saveCar(Car car) {
2525
return carRepository.save(car);
2626
}
2727

28-
@CachePut(value = "cars")
28+
@CachePut(value = "cars", key = "#car.id")
2929
public Car update(Car car) {
3030
if (carRepository.existsById(car.getId())) {
3131
return carRepository.save(car);
3232
}
33-
throw new IllegalArgumentException("A car mus have an id to be updated");
33+
throw new IllegalArgumentException("A car must have an id to be updated");
3434
}
3535

3636
@Cacheable(value = "cars")
@@ -39,7 +39,7 @@ public Car get(UUID uuid) {
3939
.orElseThrow(() -> new IllegalStateException("car with id " + uuid + " was not found"));
4040
}
4141

42-
@CacheEvict(value = "cars")
42+
@CacheEvict(value = "cars", key = "#uuid")
4343
public void delete(UUID uuid) {
4444
carRepository.deleteById(uuid);
4545
}

0 commit comments

Comments
 (0)