Jak zainicjowalibyście cache jako bean springowy którego wartości są pobierane z bazy danych ?
Czy takie coś jest ok ?
@Configuration
public class AppConfiguration {
@Autowired
private JdbcTemplate jdbcTemplate;
@Bean
public SystemsCache SystemsCache() {
return new SystemsCache(populateCache());
}
private Map<String, Integer> populateCache() {
Map<String, Integer> cache = Maps.newHashMap();
String selectSQL = "select key, value from table";
jdbcTemplate.query(selectSQL,
resultSet -> {
cache.put(resultSet.getString("key"), resultSet.getInt("value"));
});
return cache;
}
}