I wouldn't use cacheable("something") in a spring controller that involves user authentication as the cacheable is only keeping arguments. However I do not see any problem if you do not need to cache depending on the user or any request header information.
For example, in the following example, when you are getting the user logged back:
@RequestMapping(...)
@Cacheable("something")
public T analyze(@RequestParam(value = "text") String text) {
....
Object userObj =
SecurityContextHolder.getContext().getAuthentication().getPrincipal();
....
}
An option you might have in case you want to cache depending on the header is to add @RequestHeader(value="key") String val in the controller method
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With