aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--weed/util/chunk_cache/chunk_cache.go11
1 files changed, 11 insertions, 0 deletions
diff --git a/weed/util/chunk_cache/chunk_cache.go b/weed/util/chunk_cache/chunk_cache.go
index ead7a8d0b..48e4bfb0d 100644
--- a/weed/util/chunk_cache/chunk_cache.go
+++ b/weed/util/chunk_cache/chunk_cache.go
@@ -54,6 +54,10 @@ func (c *ChunkCache) GetChunk(fileId string) (data []byte) {
c.RLock()
defer c.RUnlock()
+ return c.doGetChunk(fileId)
+}
+
+func (c *ChunkCache) doGetChunk(fileId string) (data []byte) {
if data = c.memCache.GetChunk(fileId); data != nil {
return data
}
@@ -86,6 +90,13 @@ func (c *ChunkCache) SetChunk(fileId string, data []byte) {
c.Lock()
defer c.Unlock()
+ if existingData := c.doGetChunk(fileId); len(existingData)==0{
+ c.doSetChunk(fileId, data)
+ }
+}
+
+func (c *ChunkCache) doSetChunk(fileId string, data []byte) {
+
c.memCache.SetChunk(fileId, data)
if len(c.diskCaches) == 0 {