RecipeInitial
Cache Warming on Startup
Pre-populate cache on application startup
Cache Warming on Startup
Pre-populate frequently accessed data on application startup to avoid cold-start latency.
Implementation
@Component
public class CacheWarmer implements ApplicationListener<ApplicationReadyEvent> {
@Inject
private CacheService cacheService;
@Inject
private CustomerService customerService;
@Override
public void onApplicationEvent(ApplicationReadyEvent event) {
warmCustomerCache();
warmConfigCache();
}
private void warmCustomerCache() {
List<Customer> activeCustomers = customerService.findActive();
for (Customer customer : activeCustomers) {
cacheService.put(
"customer:" + customer.getId(),
customer,
Duration.ofHours(1)
);
}
log.info("Warmed {} customer records", activeCustomers.size());
}
}Best Practices
About Cache Layer
High-performance caching for qqq applications with Redis and in-memory support.
View Full DocumentationMore Cache Layer Articles
Powered by qqq