Merge remote-tracking branch 'origin/master'

This commit is contained in:
Weblate 2017-06-05 14:29:16 +02:00
commit 938c3caae5

View file

@ -160,8 +160,12 @@ public abstract class TilesCache<T> {
} }
T cacheObject = cache.get(req.tileId); T cacheObject = cache.get(req.tileId);
if (cacheObject != null) { if (cacheObject != null) {
if (isExpired(req)) {
cache.remove(req.tileId);
} else {
return cacheObject; return cacheObject;
} }
}
if (cache.size() > maxCacheSize) { if (cache.size() > maxCacheSize) {
clearTiles(); clearTiles();
} }
@ -191,10 +195,22 @@ public abstract class TilesCache<T> {
protected abstract T getTileObject(TileLoadDownloadRequest req); protected abstract T getTileObject(TileLoadDownloadRequest req);
protected void downloadIfExpired(TileLoadDownloadRequest req, long lastModified) { protected boolean isExpired(TileLoadDownloadRequest req) {
if (req.tileSource.getExpirationTimeMillis() != -1 && req.url != null && req.dirWithTiles.canRead()) {
File en = new File(req.dirWithTiles, req.tileId);
return en.exists() && isExpired(req, en.lastModified());
}
return false;
}
protected boolean isExpired(TileLoadDownloadRequest req, long lastModified) {
long time = System.currentTimeMillis(); long time = System.currentTimeMillis();
int ts = req.tileSource.getExpirationTimeMillis(); int ts = req.tileSource.getExpirationTimeMillis();
if(ts != -1 && req.url != null && time - lastModified > ts) { return ts != -1 && req.url != null && time - lastModified > ts;
}
protected void downloadIfExpired(TileLoadDownloadRequest req, long lastModified) {
if (isExpired(req, lastModified)) {
asyncLoadingThread.requestToDownload(req); asyncLoadingThread.requestToDownload(req);
} }
} }