@Cacheable object is lost in cache after @CachePut

41 Views Asked by At
    @GetMapping("/{id}")
    @Cacheable(value = "guests", key = "#id")
    @RolesAllowed({"MANAGER", "ADMIN"})
    public ResponseEntity<GuestResponse> findById(@PathVariable("id") Long id) {
        return ResponseEntity.ok(guestService.findById(id));
    }

    @CachePut(value = "guests", key = "#id")
    @PutMapping("/{id}")
    @RolesAllowed({"MANAGER", "ADMIN"})
    public ResponseEntity<HttpStatus> update(@RequestBody Map<Object, Object> fields, @PathVariable("id") Long id) {
        guestService.update(id, fields);
        return ResponseEntity.ok(HttpStatus.OK);
    }

The object is normally cached by id, but after @CachePut, although changes in the database occur, it is no longer possible to find the object from the cache. In response, I get 200 without a body.

0

There are 0 best solutions below