Changeset 31054 in osm for applications
- Timestamp:
- 2015-03-06T10:05:11+01:00 (10 years ago)
- Location:
- applications/viewer/jmapviewer/src/org/openstreetmap/gui/jmapviewer
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/viewer/jmapviewer/src/org/openstreetmap/gui/jmapviewer/OsmFileCacheTileLoader.java
r31053 r31054 49 49 private static final Charset TAGS_CHARSET = Charset.forName("UTF-8"); 50 50 51 private static final long DEFAULT_EXPIRES_TIME = 1000 * 60 * 60 * 24 * 7; 52 51 // Default expire time (i.e. maximum age of cached tile before refresh). 52 // Used when the server does not send an expires or max-age value in the http header. 53 protected static final long DEFAULT_EXPIRE_TIME = 1000 * 60 * 60 * 24 * 7; // 7 days 54 // Limit for the max-age value send by the server. 55 protected static final long EXPIRE_TIME_SERVER_LIMIT = 1000 * 60 * 60 * 24 * 28; // 4 weeks 56 // Absolute expire time limit. Cached tiles that are older will not be used, 57 // even if the refresh from the server fails. 58 protected static final long ABSOLUTE_EXPIRE_TIME_LIMIT = Long.MAX_VALUE; // unlimited 53 59 54 60 protected String cacheDirBase; … … 56 62 protected final Map<TileSource, File> sourceCacheDirMap; 57 63 58 protected long maxCacheFileAge = Long.MAX_VALUE; // max. age not limited59 64 60 65 public static File getDefaultCacheDir() throws SecurityException { … … 200 205 try { 201 206 URLConnection urlConn = loadTileFromOsm(tile); 202 if (fileMtime != null && now - fileMtime <= maxCacheFileAge) {207 if (fileMtime != null && now - fileMtime <= ABSOLUTE_EXPIRE_TIME_LIMIT) { 203 208 switch (tile.getSource().getTileUpdate()) { 204 209 case IfModifiedSince: … … 236 241 } 237 242 if (urlConn instanceof HttpURLConnection && ((HttpURLConnection)urlConn).getResponseCode() == 304) { 238 // If we areisModifiedSince or If-None-Match has been set243 // If isModifiedSince or If-None-Match has been set 239 244 // and the server answers with a HTTP 304 = "Not Modified" 240 245 switch (tile.getSource().getTileUpdate()) { … … 292 297 protected boolean isCacheValid() { 293 298 Long expires = null; 299 if (tileFile.exists()) { 300 fileMtime = tileFile.lastModified(); 301 } else if (tagsFile.exists()) { 302 fileMtime = tagsFile.lastModified(); 303 } else 304 return false; 305 294 306 try { 295 307 expires = Long.parseLong(tile.getValue("expires")); 296 308 } catch (NumberFormatException e) {} 297 309 298 if(expires != null && !expires.equals(0L)) { 299 // check by expire date set by server 310 // check by expire date set by server 311 if (expires != null && !expires.equals(0L)) { 312 // put a limit to the expire time (some servers send a value 313 // that is too large) 314 expires = Math.min(expires, fileMtime + EXPIRE_TIME_SERVER_LIMIT); 300 315 if (now > expires) { 301 316 log.log(Level.FINE, "TMS - Tile has expired -> not valid {0}", tile); … … 304 319 } else { 305 320 // check by file modification date 306 if (tileFile.exists()) { 307 // check for modification date only when tile file exists 308 // so handle properly the case, when only tags file exists 309 fileMtime = tileFile.lastModified(); 310 } else if (tagsFile.exists()) { 311 fileMtime = tagsFile.lastModified(); 312 } else 313 return false; 314 315 if (now - fileMtime > DEFAULT_EXPIRES_TIME) { 321 if (now - fileMtime > DEFAULT_EXPIRE_TIME) { 316 322 log.log(Level.FINE, "TMS - Tile has expired, maximum file age reached {0}", tile); 317 323 return false; … … 480 486 } 481 487 482 public long getMaxFileAge() {483 return maxCacheFileAge;484 }485 486 /**487 * Sets the maximum age of the local cached tile in the file system. If a488 * local tile is older than the specified file age489 * {@link OsmFileCacheTileLoader} will connect to the tile server and check490 * if a newer tile is available using the mechanism specified for the491 * selected tile source/server.492 *493 * @param maxFileAge494 * maximum age in milliseconds495 * @see #FILE_AGE_ONE_DAY496 * @see #FILE_AGE_ONE_WEEK497 * @see TileSource#getTileUpdate()498 */499 public void setCacheMaxFileAge(long maxFileAge) {500 this.maxCacheFileAge = maxFileAge;501 }502 503 488 public String getCacheDirBase() { 504 489 return cacheDirBase; -
applications/viewer/jmapviewer/src/org/openstreetmap/gui/jmapviewer/OsmTileLoader.java
r31052 r31054 117 117 for (String token: str.split(",")) { 118 118 if (token.startsWith("max-age=")) { 119 lng = Math.min( 120 Long.parseLong(token.substring(8)), 121 86400 * 31 // cap max-age at one month 122 ) * 1000 + 119 lng = Long.parseLong(token.substring(8)) * 1000 + 123 120 System.currentTimeMillis(); 124 121 }
Note:
See TracChangeset
for help on using the changeset viewer.