All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.infusers.core.cache.redis.InfuserCacheClearingComponent Maven / Gradle / Ivy

There is a newer version: 2024.12.0008
Show newest version
package com.infusers.core.cache.redis;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;

@Component
public class InfuserCacheClearingComponent {

	private Logger log = LogManager.getLogger(InfuserCacheClearingComponent.class);    

    private final ApplicationContext applicationContext;

    @Autowired
    public InfuserCacheClearingComponent(ApplicationContext applicationContext) {
        this.applicationContext = applicationContext;
    }
    
    public void clearCache() {
        String[] redisTemplateNames = applicationContext.getBeanNamesForType(RedisTemplate.class);

        for (String redisTemplateName : redisTemplateNames) {
            RedisTemplate redisTemplate = applicationContext.getBean(redisTemplateName, RedisTemplate.class);
            redisTemplate.getConnectionFactory().getConnection().flushDb();
            // Or delete specific keys if needed
            // redisTemplate.delete("key1", "key2", "key3");
        }
        // redisTemplate.delete("key1", "key2", "key3");
        
        log.info("===========================================================================================================");    				    	
		log.warn("InfuserCacheClearingComponent.clearCache() --> Redis cache cleared on Startup/Shutdown/On New user created!!");    	
		log.info("============================================================================================================");    				    	

    }
        
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy