In the latter case, a component that wishes to be updated dynamically must implement IDynamicCache interface so that data loading components that implement IDynamicCacheRefresher interface can load fresh values from the back end storage and update the component with the data loaded. This decouples component service behavior from data access logic implemented in IDynamicCacheRefresher compliant refresher components, which can be easily reused.
public class DynamicConfig implements IDynamicCache
{
private IDynamicCacheRefresher m_oRefresher = new MyDatabaseRefresher();
private void loadConfig()
{
m_oRefresher.refresh(this);
}
public void update(Map mapUpdates)
{
// mapUpdates contans all the new values loaded by refresher.
save new updates here
}
}
@since 12/15/2004