Skip to content

Commit

Permalink
Clear image cache on new server scan time
Browse files Browse the repository at this point in the history
  • Loading branch information
kaaholst committed Apr 9, 2024
1 parent 89c0452 commit c3fcb15
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 4 deletions.
13 changes: 13 additions & 0 deletions Squeezer/src/main/java/uk/org/ngo/squeezer/Preferences.java
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,9 @@ public final class Preferences {
// Optional Squeezebox Server password
private static final String KEY_MAC = "squeezer.mac";

// Timestamp when the last scan finished per server
private static final String KEY_LAST_SCAN = "lastScan";

private static final String KEY_LAST_RUN_VERSION_CODE = "lastRunVersionCode";

// The playerId that we were last connected to. e.g. "00:04:20:17:04:7f"
Expand Down Expand Up @@ -291,6 +294,7 @@ private void readServerAddress(ServerAddress serverAddress, String address, int
serverAddress.password = getStringPreference(prefix(serverAddress) + KEY_PASSWORD);
serverAddress.wakeOnLan = sharedPreferences.getBoolean(prefix(serverAddress) + KEY_WOL, false);
serverAddress.mac = Util.parseMac(getStringPreference(prefix(serverAddress) + KEY_MAC));
serverAddress.lastScan = sharedPreferences.getLong(prefix(serverAddress) + KEY_LAST_SCAN, 0);
}

private String getBssId() {
Expand Down Expand Up @@ -342,6 +346,8 @@ public static class ServerAddress {
public boolean wakeOnLan;
public byte[] mac;

public long lastScan;

private ServerAddress(String bssId, int defaultPort) {
this.defaultPort = defaultPort;
this.bssId = bssId;
Expand Down Expand Up @@ -444,6 +450,13 @@ public void saveServerAddress(ServerAddress serverAddress) {
editor.apply();
}

public void saveLastScan(ServerAddress serverAddress, long lastScan) {
serverAddress.lastScan = lastScan;
SharedPreferences.Editor editor = sharedPreferences.edit();
editor.putLong(prefix(serverAddress) + KEY_LAST_SCAN, lastScan);
editor.apply();
}

public long getLastRunVersionCode() {
return sharedPreferences.getLong(KEY_LAST_RUN_VERSION_CODE, 0);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@
import uk.org.ngo.squeezer.service.event.PlayerVolume;
import uk.org.ngo.squeezer.service.event.RegisterSqueezeNetwork;
import uk.org.ngo.squeezer.util.FluentHashMap;
import uk.org.ngo.squeezer.util.ImageFetcher;
import uk.org.ngo.squeezer.util.Reflection;
import uk.org.ngo.squeezer.util.SendWakeOnLan;

Expand Down Expand Up @@ -360,6 +361,14 @@ private void parseServerStatus(ClientSessionChannel channel, Message message) {
// so we check the server version which is also set from server status
boolean firstTimePlayersReceived = (getConnectionState().getServerVersion() == null);

final Preferences preferences = Squeezer.getPreferences();
final Preferences.ServerAddress serverAddress = preferences.getServerAddress();
long lastScan = Util.getLong(data, "lastscan");
if (lastScan > 0 && lastScan != serverAddress.lastScan) {
preferences.saveLastScan(serverAddress, lastScan);
ImageFetcher.getInstance(Squeezer.getInstance()).clearCache();
}

getConnectionState().setMediaDirs(Util.getStringArray(data, ConnectionState.MEDIA_DIRS));
getConnectionState().setServerVersion((String) data.get("version"));
Object[] item_data = (Object[]) data.get("players_loop");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -642,9 +642,7 @@ public synchronized boolean remove(String key) throws IOException {

for (int i = 0; i < valueCount; i++) {
File file = entry.getCleanFile(i);
if (!file.delete()) {
throw new IOException("failed to delete " + file);
}
deleteIfExists(file);
size -= entry.lengths[i];
entry.lengths[i] = 0;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,7 @@ public void clearCache() {

synchronized (mDiskCacheLock) {
mDiskCacheStarting = true;
if (mDiskLruCache != null && !mDiskLruCache.isClosed()) {
if (mDiskLruCache != null) {
try {
mDiskLruCache.delete();
if (BuildConfig.DEBUG) {
Expand Down

0 comments on commit c3fcb15

Please sign in to comment.