title: Force Paging Library to make Api Request
body: <p>I have successfully implemented a PagedList.BoundaryCallback, which loads a list of upcoming movies from "themoviedb" database, and saves the response into the database.
  But it does not work the way I want it. Since the request return a list of upcoming movies, the response changes frequently. But if I already have data in my database, the onZeroItemsLoaded() method is not called.
  My question is, how can I force the data source, or this boundary callback to always make an api request, and refresh the content of my database from the network?</p>
  
  <pre><code>public class UpcomingMoviesBoundaryCallback extends PagedList.BoundaryCallback&lt;MovieListItemEntity&gt; {
  public static final String TAG = UpcomingMoviesBoundaryCallback.class.getSimpleName();
  
  private UpcomingMoviesRepository upcomingMoviesRepository;
  private int page = 1;
  
  public UpcomingMoviesBoundaryCallback(UpcomingMoviesRepository upcomingMoviesRepository) {
      this.upcomingMoviesRepository = upcomingMoviesRepository;
  }
  
  @Override
  public void onZeroItemsLoaded() {
      super.onZeroItemsLoaded();
      Log.d(TAG, "onZeroItemsLoaded: ");
      load();
  }
  
  @Override
  public void onItemAtEndLoaded(@NonNull MovieListItemEntity itemAtEnd) {
      super.onItemAtEndLoaded(itemAtEnd);
      Log.d(TAG, "onItemAtEndLoaded: ");
      load();
  }
  
  @SuppressLint("CheckResult")
  private void load() {
      upcomingMoviesRepository.getUpcoming(page)
              .doOnSuccess(result -&gt; {
                  upcomingMoviesRepository.saveUpcomingMovies(result);
                  page = result.getPage() + 1;
              })
              .subscribeOn(Schedulers.io())
              .subscribe(result -&gt; {
                  Log.d(TAG, "load: " + result);
              }, error -&gt; {
                  Log.d(TAG, "load: error", error);
              });
  }
  </code></pre>
  
  <p>}</p>
  
  <pre><code>public class UpcomingMoviesRepositoryImpl implements UpcomingMoviesRepository {
  private static final String TAG = UpcomingMoviesRepository.class.getSimpleName();
  
  private MovieResponseMapper movieResponseMapper = new MovieResponseMapper();
  private MovieAppApi mMovieAppApi;
  private UpcomingDao mUpcomingDao;
  
  public UpcomingMoviesRepositoryImpl(MovieAppApi mMovieAppApi, UpcomingDao mUpcomingDao) {
      this.mMovieAppApi = mMovieAppApi;
      this.mUpcomingDao = mUpcomingDao;
  }
  
  @Override
  public Single&lt;MovieListResponse&gt; getUpcoming(int page) {
      return mMovieAppApi.upcoming(page);
  }
  
  @Override
  public Single&lt;MovieListResponse&gt; getUpcoming() {
      return mMovieAppApi.upcoming();
  }
  
  @Override
  public void saveUpcomingMovies(MovieListResponse movieListResponse) {
      Executors.newSingleThreadExecutor().execute(() -&gt; {
          long[] inseted = mUpcomingDao.save(movieResponseMapper.map2(movieListResponse.getResults()));
          Log.d(TAG, "saveUpcomingMovies: " + inseted.length);
      });
  }
  
  @Override
  public LiveData&lt;PagedList&lt;MovieListItemEntity&gt;&gt; getUpcomingLiveData() {
      PagedList.Config config = new PagedList.Config.Builder()
              .setEnablePlaceholders(true)
              .setPageSize(12)
              .build();
      DataSource.Factory&lt;Integer, MovieListItemEntity&gt; dataSource = mUpcomingDao.upcoming();
      LivePagedListBuilder builder =
              new LivePagedListBuilder(dataSource, config)
              .setBoundaryCallback(new UpcomingMoviesBoundaryCallback(this));
      return builder.build();
  }
  </code></pre>
  
  <p>}</p>