Changeset 31053 in osm for applications


Ignore:
Timestamp:
2015-03-06T02:36:22+01:00 (10 years ago)
Author:
bastik
Message:

see #josm11193 - handle the case X-VE-Tile-Info: no-tile and no max-age header (use mtime from tags file)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • applications/viewer/jmapviewer/src/org/openstreetmap/gui/jmapviewer/OsmFileCacheTileLoader.java

    r31052 r31053  
    132132        File tileCacheDir;
    133133        File tileFile = null;
     134        File tagsFile = null;
    134135        Long fileMtime = null;
    135136        Long now = null; // current time in milliseconds (keep consistent value for the whole run)
     
    155156            now = System.currentTimeMillis();
    156157            tileCacheDir = getSourceCacheDir(tile.getSource());
     158            tileFile = getTileFile();
     159            tagsFile = getTagsFile();
    157160
    158161            loadTagsFromFile();
    159162
    160             if (isTileFileValid() && (isNoTileAtZoom() || loadTileFromFile())) {
     163            if (isCacheValid() && (isNoTileAtZoom() || loadTileFromFile())) {
    161164                log.log(Level.FINE, "TMS - found in tile cache: {0}", tile);
    162165                tile.setLoaded(true);
     
    287290        }
    288291
    289         protected boolean isTileFileValid() {
     292        protected boolean isCacheValid() {
    290293            Long expires = null;
    291294            try {
     
    305308                    // so handle properly the case, when only tags file exists
    306309                    fileMtime = tileFile.lastModified();
    307                     if (now - fileMtime > DEFAULT_EXPIRES_TIME) {
    308                         log.log(Level.FINE, "TMS - Tile has expired, maximum file age reached {0}", tile);
    309                         return false;
    310                     }
     310                } else if (tagsFile.exists()) {
     311                    fileMtime = tagsFile.lastModified();
     312                } else
     313                    return false;
     314
     315                if (now - fileMtime > DEFAULT_EXPIRES_TIME) {
     316                    log.log(Level.FINE, "TMS - Tile has expired, maximum file age reached {0}", tile);
     317                    return false;
    311318                }
    312319            }
     
    337344                log.log(Level.WARNING, "TMS - Error while loading image from tile cache: {0}; {1}", new Object[]{e.getMessage(), tile});
    338345                tileFile.delete();
    339                 File tileMetaData = getTagsFile();
    340                 if (tileMetaData.exists())
    341                     tileMetaData.delete();
     346                if (tagsFile.exists()) {
     347                    tagsFile.delete();
     348                }
    342349                tileFile = null;
    343350                fileMtime = null;
     
    454461
    455462        protected boolean loadTagsFromFile() {
    456             tileFile = getTileFile();
    457463            File tagsFile = getTagsFile();
    458464            try (BufferedReader f = new BufferedReader(new InputStreamReader(new FileInputStream(tagsFile), TAGS_CHARSET))) {
Note: See TracChangeset for help on using the changeset viewer.