Null key returned for cache operation solution
1. Background description
Technology stack: Springboot(2.5.14) + MQTT(5.x) + Cache + MySQL
There is a method in the project: query device details according to the device id, which is a very frequently used function. In order to reduce the pressure on the database, it is natural to think of using caching technology.
2. Error content
Null key returned for cache operation (maybe you are using named params on classes without debug info?) Builder
The detailed error information is shown in the figure below:
Three, the reason for the error
@Cacheable(key = "#id", unless = "#result==null")
The value of the key in the annotation, that is, the id value is null, that is, the input parameter id of the method is empty. When calling the method, a null value cannot be passed. If a null value is passed in, the above error will be reported.
4. Solutions
When calling this method, first determine whether the id is empty, and then call this method when the id is not empty.
for example:
This article is over!