Merge remote-tracking branch 'origin/master'
This commit is contained in:
commit
938c3caae5
1 changed files with 19 additions and 3 deletions
|
@ -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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue