CacheConfig.java
package com.archiweb.config;
import org.springframework.cache.CacheManager;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.cache.concurrent.ConcurrentMapCacheManager;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.Scheduled;
@Configuration
@EnableCaching
public class CacheConfig {
@Bean
public CacheManager cacheManager() {
ConcurrentMapCacheManager cacheManager = new ConcurrentMapCacheManager("globalStats", "demographicsStats", "winsStats");
// Permettre le stockage de valeurs null temporairement pour éviter les erreurs
cacheManager.setAllowNullValues(true);
return cacheManager;
}
/**
* Vide le cache toutes les 5 minutes pour avoir des données à jour
* Les stats ne changent pas si fréquemment, donc 5 minutes est un bon compromis
*/
@CacheEvict(value = {"globalStats", "demographicsStats", "winsStats"}, allEntries = true)
@Scheduled(fixedRate = 300000) // 5 minutes en millisecondes
public void evictStatsCache() {
// Méthode vide, l'annotation @CacheEvict fait le travail
}
}