Spring не кэширует мою функцию, когда я использую ключ по умолчанию, такой как -
@PostMapping("getDashboardDataNew")
@Cacheable(value="myDash")
public DashboardDto getHomeDashboardDataNew(@RequestBody DashboardRequest dashboardRequest) {
LOGGER.info(" Get All the Dashboard Information : ");
//code
return dashboardDto;
}
Но когда я предоставляю пользовательский ключ, используя sPEL, он кэширует ответ, например.
@PostMapping("getDashboardDataNew")
@Cacheable(value="myDash", key="#dashboardRequest.level")
public DashboardDto getHomeDashboardDataNew(@RequestBody DashboardRequest dashboardRequest) {
LOGGER.info(" Get All the Dashboard Information : ");
//code
return dashboardDto;
}
Полезная нагрузка запроса всегда-
{"fromDate": null, "toDate": null, "theme": null, "activity": null, "level": 1, "levelValue": null, "state": null, "district": null}
Даже после автоматического создания равных и хэш-кода с использованием затмения пружина не кэширует значение.Ниже приведены автоматически сгенерированные коды
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((activity == null) ? 0 : activity.hashCode());
result = prime * result + ((fromDate == null) ? 0 : fromDate.hashCode());
result = prime * result + ((level == null) ? 0 : level.hashCode());
result = prime * result + ((levelValue == null) ? 0 : levelValue.hashCode());
result = prime * result + ((organizer == null) ? 0 : organizer.hashCode());
result = prime * result + ((theme == null) ? 0 : theme.hashCode());
result = prime * result + ((toDate == null) ? 0 : toDate.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
DashboardRequest other = (DashboardRequest) obj;
if (activity == null) {
if (other.activity != null)
return false;
} else if (!activity.equals(other.activity))
return false;
if (fromDate == null) {
if (other.fromDate != null)
return false;
} else if (!fromDate.equals(other.fromDate))
return false;
if (level == null) {
if (other.level != null)
return false;
} else if (!level.equals(other.level))
return false;
if (levelValue == null) {
if (other.levelValue != null)
return false;
} else if (!levelValue.equals(other.levelValue))
return false;
if (organizer == null) {
if (other.organizer != null)
return false;
} else if (!organizer.equals(other.organizer))
return false;
if (theme == null) {
if (other.theme != null)
return false;
} else if (!theme.equals(other.theme))
return false;
if (toDate == null) {
if (other.toDate != null)
return false;
} else if (!toDate.equals(other.toDate))
return false;
return true;
}
Я не изменяю полезную нагрузку запроса.