Index: trunk/src/org/openstreetmap/josm/data/cache/JCSCachedTileLoaderJob.java
===================================================================
--- trunk/src/org/openstreetmap/josm/data/cache/JCSCachedTileLoaderJob.java	(revision 13777)
+++ trunk/src/org/openstreetmap/josm/data/cache/JCSCachedTileLoaderJob.java	(revision 13778)
@@ -437,25 +437,42 @@
         CacheEntryAttributes ret = new CacheEntryAttributes();
 
-        Long lng = urlConn.getExpiration();
-        if (lng.equals(0L)) {
-            try {
-                String str = urlConn.getHeaderField("Cache-Control");
-                if (str != null) {
-                    for (String token: str.split(",")) {
-                        if (token.startsWith("max-age=")) {
-                            lng = TimeUnit.SECONDS.toMillis(Long.parseLong(token.substring(8))) + System.currentTimeMillis();
-                        }
+        /*
+         * according to https://www.ietf.org/rfc/rfc2616.txt Cache-Control takes precedence over max-age
+         * max-age is for private caches, s-max-age is for shared caches. We take any value that is larger
+         */
+        Long expiration = 0L;
+        String cacheControl = urlConn.getHeaderField("Cache-Control");
+        if (cacheControl != null) {
+            for (String token: cacheControl.split(",")) {
+                try {
+                    if (token.startsWith("max-age=")) {
+                        expiration = Math.max(expiration,
+                                TimeUnit.SECONDS.toMillis(Long.parseLong(token.substring("max-age=".length())))
+                                + System.currentTimeMillis()
+                                );
                     }
+                    if (token.startsWith("s-max-age=")) {
+                        expiration = Math.max(expiration,
+                                TimeUnit.SECONDS.toMillis(Long.parseLong(token.substring("s-max-age=".length())))
+                                + System.currentTimeMillis()
+                                );
+                    }
+                } catch (NumberFormatException e) {
+                    // ignore malformed Cache-Control headers
+                    Logging.trace(e);
                 }
-            } catch (NumberFormatException e) {
-                // ignore malformed Cache-Control headers
-                Logging.trace(e);
-            }
-            if (lng.equals(0L)) {
-                lng = System.currentTimeMillis() + DEFAULT_EXPIRE_TIME;
-            }
-        }
-
-        ret.setExpirationTime(Math.max(minimumExpiryTime + System.currentTimeMillis(), lng));
+            }
+        }
+
+        if (expiration.equals(0L)) {
+            expiration = urlConn.getExpiration();
+        }
+
+        // if nothing is found - set default
+        if (expiration.equals(0L)) {
+            expiration = System.currentTimeMillis() + DEFAULT_EXPIRE_TIME;
+        }
+
+        ret.setExpirationTime(Math.max(minimumExpiryTime + System.currentTimeMillis(), expiration));
         ret.setLastModification(now);
         ret.setEtag(urlConn.getHeaderField("ETag"));
