I tried the annotation @CachePut in the method updateCategoryCacheForCountry and it wasn’t working. But
when doing so programatically by getting the cache and using .put it works fine. What could be the reason?
I’m using Spring Cache. The method is being called by a @Scheduled method.
// @CachePut(key = "#country")
public CacheCategories updateCategoryCacheForCountry(String country) {
CacheCategories categories = requestDirectus(country);
Cache categoriesCache = cacheManager.getCache("categories");
categoriesCache.put(country, categories);
return categories;
}
@Scheduled(fixedDelay = 300000) //5m
protected void updateCategories() {
String[] countries = {esConfig.getStoreArgentina(), esConfig.getStoreChile(), esConfig.getStoreParaguay(), esConfig.getStoreBolivia()};
for (String country : countries) {
updateCategoryCacheForCountry(country);
}
}
@EnableCaching
@Configuration
@EnableScheduling
public class CacheConfig {
@Bean // Configuramos el cache a utilizar
public CacheManager cacheManager() {
SimpleCacheManager cacheManager = new SimpleCacheManager();
cacheManager.setCaches(Arrays.asList(
new ConcurrentMapCache("categories"),
new ConcurrentMapCache("token")
));
return cacheManager;
}
}