Chris Lu
5 years ago
3 changed files with 41 additions and 34 deletions
-
27other/java/client/src/main/java/seaweedfs/client/ChunkCache.java
-
43other/java/client/src/main/java/seaweedfs/client/SeaweedRead.java
-
3other/java/client/src/main/java/seaweedfs/client/SeaweedWrite.java
@ -0,0 +1,27 @@ |
|||
package seaweedfs.client; |
|||
|
|||
import com.google.common.cache.Cache; |
|||
import com.google.common.cache.CacheBuilder; |
|||
|
|||
import java.util.concurrent.TimeUnit; |
|||
|
|||
public class ChunkCache { |
|||
|
|||
private final Cache<String, byte[]> cache; |
|||
|
|||
public ChunkCache(int maxEntries) { |
|||
this.cache = CacheBuilder.newBuilder() |
|||
.maximumSize(maxEntries) |
|||
.expireAfterAccess(1, TimeUnit.HOURS) |
|||
.build(); |
|||
} |
|||
|
|||
public byte[] getChunk(String fileId) { |
|||
return this.cache.getIfPresent(fileId); |
|||
} |
|||
|
|||
public void setChunk(String fileId, byte[] data) { |
|||
this.cache.put(fileId, data); |
|||
} |
|||
|
|||
} |
Write
Preview
Loading…
Cancel
Save
Reference in new issue