Browse Source

cache

master
gsd 1 week ago
parent
commit
610f34f6a8
  1. 17
      src/main/java/app/configurations/AppCacheConfig.java

17
src/main/java/app/configurations/AppCacheConfig.java

@ -2,10 +2,13 @@ package app.configurations;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.Cache;
import org.springframework.cache.CacheManager;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.cache.concurrent.ConcurrentMapCacheManager;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.Scheduled;
@ -21,6 +24,10 @@ public class AppCacheConfig {
public static final String g_vip = "graphs.vip";
public static final String g_online = "graphs.online";
public static final String g_usertime_connections = "graphs.usertime.connections";
private static final String[] g_ = new String[]{g_usertime, g_vip, g_online, g_usertime_connections};
@Autowired
private ApplicationContext applicationContext;
@Bean
public CacheManager cacheManager() {
@ -38,8 +45,14 @@ public class AppCacheConfig {
purgeGraphCache();
}
@CacheEvict(value = {g_usertime, g_vip, g_online, g_usertime_connections}, allEntries = true)
public void purgeGraphCache() {
logger.info("Cache clean of graphs");
CacheManager cacheManager = applicationContext.getBean(CacheManager.class);
for (String s : g_) {
Cache cache = cacheManager.getCache(s);
if (cache != null) {
logger.info("Clean cache: " + s);
cache.clear();
}
}
}
}

Loading…
Cancel
Save