option to disable chunk cache
This commit is contained in:
@@ -10,6 +10,9 @@ public class ChunkCache {
|
|||||||
private final Cache<String, byte[]> cache;
|
private final Cache<String, byte[]> cache;
|
||||||
|
|
||||||
public ChunkCache(int maxEntries) {
|
public ChunkCache(int maxEntries) {
|
||||||
|
if (maxEntries == 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
this.cache = CacheBuilder.newBuilder()
|
this.cache = CacheBuilder.newBuilder()
|
||||||
.maximumSize(maxEntries)
|
.maximumSize(maxEntries)
|
||||||
.expireAfterAccess(1, TimeUnit.HOURS)
|
.expireAfterAccess(1, TimeUnit.HOURS)
|
||||||
@@ -17,10 +20,16 @@ public class ChunkCache {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public byte[] getChunk(String fileId) {
|
public byte[] getChunk(String fileId) {
|
||||||
|
if (this.cache == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
return this.cache.getIfPresent(fileId);
|
return this.cache.getIfPresent(fileId);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setChunk(String fileId, byte[] data) {
|
public void setChunk(String fileId, byte[] data) {
|
||||||
|
if (this.cache == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
this.cache.put(fileId, data);
|
this.cache.put(fileId, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user