Ticket #11193: expires-version2.patch
File expires-version2.patch, 2.4 KB (added by , 10 years ago) |
---|
-
src/org/openstreetmap/gui/jmapviewer/OsmFileCacheTileLoader.java
66 66 } catch (SecurityException e) { 67 67 log.log(Level.WARNING, 68 68 "Failed to access system property ''java.io.tmpdir'' for security reasons. Exception was: " 69 + e.toString());69 + e.toString()); 70 70 throw e; // rethrow 71 71 } 72 72 try { … … 248 248 } 249 249 } 250 250 251 // set file modification date to Expires / max-age date but subtract maxCacheFileAge - so 252 // Expires/cache-control headers will be honored 253 Long lng = urlConn.getExpiration(); 254 if (lng == null) { 255 String str = urlConn.getHeaderField("Cache-Control"); 256 if (str != null) { 257 for (String token: str.split(",")) { 258 if (token.startsWith("max-age=")) { 259 lng = Long.parseLong(token.substring(8))+System.currentTimeMillis(); 260 } 261 } 262 } 263 } 264 if (lng != null) { 265 tileFile.setLastModified(lng - maxCacheFileAge); 266 } 267 268 251 269 loadTileMetadata(tile, urlConn); 252 270 saveTagsToFile(); 253 271 … … 295 313 fileMtime = tileFile.lastModified(); 296 314 if (now - fileMtime > maxAge) 297 315 return false; 298 316 299 317 if ("no-tile".equals(tile.getValue("tile-info"))) { 300 318 tile.setError("No tile at this zoom level"); 301 319 if (tileFile.exists()) { … … 405 423 File file = getTileFile(); 406 424 file.getParentFile().mkdirs(); 407 425 try ( 408 FileOutputStream f = new FileOutputStream(file)409 ) {426 FileOutputStream f = new FileOutputStream(file) 427 ) { 410 428 f.write(rawData); 411 429 } catch (Exception e) { 412 430 log.log(Level.SEVERE, "Failed to save tile content: {0}", e.getLocalizedMessage());