Spring Cache

Jan 25, 2019 15:13



// use spring cache

@Configuration
@EnableCaching
public class CachingConfig {
public static final String CACHE_NAME_X = "x";
@Bean
public CacheManager cacheManager() {
SimpleCacheManager cacheManager = new SimpleCacheManager();
cacheManager.setCaches(asList(new ConcurrentMapCache(CACHE_NAME_X)));
return cacheManager;
}
}

@Component
public class ProvisionReader {

@Cacheable(value = CachingConfig.CACHE_NAME_X, key = "#arg2")
public Data read(Arg arg1, String arg2) {
System.out.println("CALL !!!");
return something;
}

@Scheduled(fixedDelay = 5_000)
@CacheEvict(value = CachingConfig.CACHE_NAME_X, allEntries = true)
public void resetCache() {
System.out.println("RESET CACHE");
}
}

#arg2, программирование

Previous post Next post
Up