Skip to content

Commit

Permalink
Force all game cache entries to be refreshed at least every week, even
Browse files Browse the repository at this point in the history
if the game version hasn't been changed.
  • Loading branch information
samschreiber committed Oct 29, 2013
1 parent 14dd854 commit f11e24f
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions src/org/ggp/base/util/game/CloudGameRepository.java
Original file line number Diff line number Diff line change
Expand Up @@ -178,23 +178,25 @@ public void run() {
if (bundledMetadata != null) {
Set<String> unchangedKeys = new HashSet<String>();
for (String theKey : theGameKeys) {
try {
try {
Game myGameVersion = loadGameFromCache(theKey);
if (myGameVersion == null)
continue;

String remoteGameURL = remoteRepository.getGameURL(theKey);
int remoteVersion = bundledMetadata.getJSONObject(theKey).getInt("version");
String remoteVersionedGameURL = RemoteGameRepository.addVersionToGameURL(remoteGameURL, remoteVersion);

if (myGameVersion.getRepositoryURL().equals(remoteVersionedGameURL)) {

// Skip updating the game cache entry if the version is the same
// and the cache entry was written less than a week ago.
if (myGameVersion.getRepositoryURL().equals(remoteVersionedGameURL) &&
getCacheEntryAge(theKey) < 604800000) {
unchangedKeys.add(theKey);
}
} catch (Exception e) {
continue;
}
}
theGameKeys.removeAll(unchangedKeys);
}

// Start threads to update every entry in the cache (or at least verify
Expand Down Expand Up @@ -261,6 +263,14 @@ private synchronized Game loadGameFromCache(String theKey) {
if (theLine == null) return null;
return Game.loadFromJSON(theLine);
}

private synchronized long getCacheEntryAge(String theKey) {
File theGameFile = new File(theCacheDirectory, theKey + ".zip");
if (theGameFile.exists()) {
return System.currentTimeMillis() - theGameFile.lastModified();
}
return System.currentTimeMillis();
}

// ================================================================

Expand Down

0 comments on commit f11e24f

Please sign in to comment.