@WorkerThread
    @SuppressWarnings("PMD.NPathComplexity")
    public static boolean storeCache(@Nullable final Geocache origCache, @Nullable final String geocode, @NonNull final Set<Integer> lists, final boolean forceRedownload, @Nullable final DisposableHandler handler) {
        try {
            final Geocache cache;
            // get cache details, they may not yet be complete
            if (origCache != null) {
                // only reload the cache if it was already stored or doesn't have full details (by checking the description)
                if (origCache.isOffline() || StringUtils.isBlank(origCache.getDescription())) {
                    final SearchResult search = searchByGeocode(origCache.getGeocode(), null, false, handler);
                    cache = search != null ? search.getFirstCacheFromResult(LoadFlags.LOAD_CACHE_OR_DB) : origCache;
                    if (search != null && search.getError() != StatusCode.NO_ERROR) {
                        DisposableHandler.sendShowStatusToast(handler, search.getError().getErrorStringId());
                    }
                } else {
                    cache = origCache;
                }
            } else if (StringUtils.isNotBlank(geocode)) {
                final SearchResult search = searchByGeocode(geocode, null, forceRedownload, handler);
                cache = search != null ? search.getFirstCacheFromResult(LoadFlags.LOAD_CACHE_OR_DB) : null;
                if (search != null && search.getError() != StatusCode.NO_ERROR) {
                    DisposableHandler.sendShowStatusToast(handler, search.getError().getErrorStringId());
                }
            } else {
                cache = null;
            }

            if (cache == null) {
                if (handler != null) {
                    handler.sendMessage(Message.obtain());
                }

                return false;
            }

            if (DisposableHandler.isDisposed(handler)) {
                return false;
            }

            final HtmlImage imgGetter = new HtmlImage(cache.getGeocode(), false, true, forceRedownload);

            // store images from description
            if (StringUtils.isNotBlank(cache.getDescription())) {
                HtmlCompat.fromHtml(cache.getDescription(), HtmlCompat.FROM_HTML_MODE_LEGACY, imgGetter, null);
            }

            if (DisposableHandler.isDisposed(handler)) {
                return false;
            }

            // store spoilers
            if (CollectionUtils.isNotEmpty(cache.getSpoilers())) {
                for (final Image oneSpoiler : cache.getSpoilers()) {
                    imgGetter.getDrawable(oneSpoiler.getUrl());
                }
            }

            if (DisposableHandler.isDisposed(handler)) {
                return false;
            }

            // store images from logs
            if (Settings.isStoreLogImages()) {
                for (final LogEntry log : cache.getLogs()) {
                    if (log.hasLogImages()) {
                        for (final Image oneLogImg : log.logImages) {
                            imgGetter.getDrawable(oneLogImg.getUrl());
                        }
                    }
                }
            }

            if (DisposableHandler.isDisposed(handler)) {
                return false;
            }

            // Need to wait for images loading since HtmlImage.getDrawable is non-blocking here
            imgGetter.waitForEndCompletable(null).blockingAwait();

            cache.setLists(lists);

            DataStore.saveCache(cache, EnumSet.of(SaveFlag.DB));

            if (DisposableHandler.isDisposed(handler)) {
                return false;
            }

            if (handler != null) {
                handler.sendEmptyMessage(DisposableHandler.DONE);
            }
            return true;
        } catch (final Exception e) {
            Log.e("Geocache.storeCache", e);
            return false;
        }
    }
Download and store a cache synchronous

@param origCache       the cache which should be refreshed, can be null
@param geocode         the geocode of the cache which should be downloaded
@param lists           to which lists the cache should be added
@param forceRedownload whether the cache should be re-downloaded, even if it's already stored offline
@param handler         a handler to receive status updates, can be null
@return true, if the cache was stored successfully
main/src/main/java/cgeo/geocaching/models/Geocache.java