Ticket #11193: expires-version1.patch
File expires-version1.patch, 3.1 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 { … … 293 293 loadTagsFromFile(); 294 294 295 295 fileMtime = tileFile.lastModified(); 296 if (now - fileMtime > maxAge) 297 return false; 298 296 if (tile.getValue("expires") != null) { 297 try { 298 // if there was Expires/Cache-Control header provided, check against it 299 if (now > Long.parseLong(tile.getValue("expires"))) 300 return false; 301 } catch (NumberFormatException e) {} 302 } else { 303 // otherwise check against static cache policy 304 if (now - fileMtime > maxAge) 305 return false; 306 } 299 307 if ("no-tile".equals(tile.getValue("tile-info"))) { 300 308 tile.setError("No tile at this zoom level"); 301 309 if (tileFile.exists()) { … … 405 413 File file = getTileFile(); 406 414 file.getParentFile().mkdirs(); 407 415 try ( 408 FileOutputStream f = new FileOutputStream(file)409 ) {416 FileOutputStream f = new FileOutputStream(file) 417 ) { 410 418 f.write(rawData); 411 419 } catch (Exception e) { 412 420 log.log(Level.SEVERE, "Failed to save tile content: {0}", e.getLocalizedMessage()); -
src/org/openstreetmap/gui/jmapviewer/OsmTileLoader.java
108 108 if (str != null) { 109 109 tile.putValue("tile-info", str); 110 110 } 111 112 // get Expiration or Cache-Control: max-age= value 113 Long lng = urlConn.getExpiration(); 114 if (lng == null) { 115 str = urlConn.getHeaderField("Cache-Control"); 116 if (str != null) { 117 for (String token: str.split(",")) { 118 if (token.startsWith("max-age=")) { 119 lng = Long.parseLong(token.substring(8))+System.currentTimeMillis(); 120 } 121 } 122 } 123 } 124 if (lng != null) { 125 tile.putValue("expires", lng.toString()); 126 } 111 127 } 112 128 113 129 protected void prepareHttpUrlConnection(HttpURLConnection urlConn) {