San
San

Reputation: 161

Refresh bean in spring with interval

I have developed a springMVC application which uses ehcache. The cache items are fetched from another system. I would not know when will the items get change in the next system. I need to periodically trigger a webservice call say 5 hrs or 3 hrs interval in order to fetch the changed items and update in the cache.

Is it possible to refresh to bean in paricular interval so that upon refreshing i will invoke the webservices and refresh the cache.

Upvotes: 0

Views: 2811

Answers (1)

WeMakeSoftware
WeMakeSoftware

Reputation: 9162

Probably the easiest way to solve your problem is to create a periodically executed job that triggers the WebService call.

Something like this:

@Service
public class WebServiceRefreshService {

  public static final int SERVICE_CALL_RATE_MILLISECONDS = 60 * 1000;

 @Scheduled(fixedRate = SERVICE_CALL_RATE_MILLISECONDS)
    public void refreshFromWebService() {
      //do stuff
    }
}

Upvotes: 1

Related Questions