Is it possible to configure Spring @Cacheable so that if there are no cache gaps to the cached method, it will be blocked until the caching method is executed once and the cache is full?
In my case, I am dealing with data from db that does not change often actually, if this data changes, the application will need to be restarted. I can create @PostConstruct methods and initialize the data as each service starts, but it does not seem "elegant" like the @Cacheable annotation.
I plan to use EhCache with Spring @Cacheable annotation.
update:
Here are some issues that I encountered when trying to use @PostConstruct if anyone else came across these problems. @PostConstruct methods cannot be @Transactional , because they are launched after the properties of the object are set, and not after the Spring context is configured. Thus, you cannot assume that the TX dispatcher is configured and configured at the time the @PostConstruct method is @PostConstruct . The workaround for this is to implement the ApplicationListener and manually enter the TransactionTemplate ... etc. A lot of extra work that is simplified with @Cacheable .
source share