1

I have service:

@Service
public class ErrMessageServiceImpl implements ErrMessageService {

  private final ErrMessageRepository errMessageRepository;

  public ErrMessageServiceImpl(ErrMessageRepository errMessageRepository) {
    this.errMessageRepository = errMessageRepository;
  }

  @Override
  @Cacheable("errorMessages")
  public ErrMessage getOneByCode(int code) {
    return errMessageRepository.getOneByCode(code);
  }
}

I read that this default implementation work with ConcurrentHashMap

Initially, the project does not define any caching library so the abstraction works on simple ConcurrentHashMap-based caches. You can try out your favorite caching library as explained below. link

All work fine. But now I need refresh Cache every 10 minutes. But I not understand how can I do it? I suspect I need use some provider and configure it - Caffeine, Redis and etc. Or I can configure default ConcurrentHashMap and set refresh interval?

ip696
  • 6,574
  • 12
  • 65
  • 128
  • You can do this even without configuring any cachemanager as indicated by most of the answers in the link. Check `@Scheduled` and @CacheEvict – pvpkiran Aug 16 '18 at 08:50
  • There is no option for auto-refresh/auto clear in @Cacheable. But you can write your own schedule for this purpose. Follow this https://blog.jdriven.com/2016/06/building-your-own-self-refreshing-cache-in-java-ee/ – Yogi Aug 16 '18 at 08:51

0 Answers0