Quantcast
Channel: Active questions tagged redis+java - Stack Overflow
Viewing all articles
Browse latest Browse all 2203

Java Spring Boot how to set Redis cache key for multiple query string parameters on controller

$
0
0

With the following Controller method:

    @GetMapping("/books")    public ResponseEntity<List<Book>> getBooksByTitleOrAuthor(        @RequestParam(required = false) String title,        @RequestParam(required = false) String author) {        if ((title== null || title.isEmpty()) && (author == null || author.isEmpty()))            return new ResponseEntity<>(HttpStatus.BAD_REQUEST);        if (author != null) {            Logger.info("GET /books?author="+ author);            return bookService.getByAuthor(author)        }        Logger.info("GET /books?title="+ title);        return bookService.getByTitle(title));    }

I can call the endpoint with:

/books?title=SomeBookTitle

or

/books?author=SomeAuthor

How can I set the Redis key with either title or author here using @Cacheable?


Viewing all articles
Browse latest Browse all 2203

Trending Articles