Skip to content

Commit 72fa14a

Browse files
committed
Fixed #71
1 parent 0a8fd3d commit 72fa14a

1 file changed

Lines changed: 12 additions & 0 deletions

File tree

core/src/main/java/xyz/gianlu/librespot/cache/CacheManager.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,12 @@ public class CacheManager implements Closeable {
3636

3737
public CacheManager(@NotNull Configuration conf) throws IOException {
3838
this.enabled = conf.cacheEnabled();
39+
if (!enabled) {
40+
parent = null;
41+
table = null;
42+
return;
43+
}
44+
3945
this.parent = conf.cacheDir();
4046

4147
if (!parent.exists() && !parent.mkdir())
@@ -70,6 +76,8 @@ private static File getCacheFile(@NotNull File parent, @NotNull String hex) thro
7076
}
7177

7278
private void doCleanUp() throws SQLException, IOException {
79+
if (!enabled) return;
80+
7381
try (PreparedStatement statement = table.prepareStatement("SELECT fileId, value FROM Headers WHERE id=?")) {
7482
statement.setString(1, Utils.byteToHex(HEADER_TIMESTAMP));
7583

@@ -83,6 +91,8 @@ private void doCleanUp() throws SQLException, IOException {
8391
}
8492

8593
private void remove(@NotNull String fileIdHex) throws SQLException, IOException {
94+
if (!enabled) return;
95+
8696
try (PreparedStatement statement = table.prepareStatement("DELETE FROM Headers WHERE fileId=?")) {
8797
statement.setString(1, fileIdHex);
8898
statement.executeUpdate();
@@ -101,6 +111,8 @@ private void remove(@NotNull String fileIdHex) throws SQLException, IOException
101111
}
102112

103113
private void createTablesIfNeeded() throws SQLException {
114+
if (!enabled) return;
115+
104116
try (Statement statement = table.createStatement()) {
105117
statement.execute("CREATE TABLE IF NOT EXISTS Chunks ( `fileId` TEXT NOT NULL, `chunkIndex` INTEGER NOT NULL, `available` INTEGER NOT NULL, PRIMARY KEY(`fileId`,`chunkIndex`) )");
106118
}

0 commit comments

Comments
 (0)