I am trying to find a way to cache some data for some specific period of time.
I am aware of @Cachable annotation, however I didn't find any way to get cache purged after some specific period of time.
@GetMapping("/{lang}.{format}")
@Timed
public ResponseEntity<Object> getLocalizedMessages(@PathVariable String lang,
@PathVariable String format,
@RequestParam("buildTimestamp") long buildTimestamp) throws InvalidArgumentException {
Map<String, Object> messages = this.localeMessageService.getMessagesForLocale(lang);
if (FORMAT_JSON.equals(format)) {
String jsonMessages = new PropertiesToJsonConverter().convertFromValuesAsObjectMap(messages);
return new ResponseEntity<>(jsonMessages, HttpStatus.OK);
}
return new ResponseEntity<>(messages, HttpStatus.OK);
}
Here is my rest method, I need to cache data based on the unix time, a timestamp passed as an argument, so for instance if an hour has passed the cache should be invalidated.