Browse Source

avoid duplicated setting chunks into cache

pull/1273/head
Chris Lu 5 years ago
parent
commit
2a1f396df5
  1. 11
      weed/util/chunk_cache/chunk_cache.go

11
weed/util/chunk_cache/chunk_cache.go

@ -54,6 +54,10 @@ func (c *ChunkCache) GetChunk(fileId string) (data []byte) {
c.RLock() c.RLock()
defer c.RUnlock() defer c.RUnlock()
return c.doGetChunk(fileId)
}
func (c *ChunkCache) doGetChunk(fileId string) (data []byte) {
if data = c.memCache.GetChunk(fileId); data != nil { if data = c.memCache.GetChunk(fileId); data != nil {
return data return data
} }
@ -86,6 +90,13 @@ func (c *ChunkCache) SetChunk(fileId string, data []byte) {
c.Lock() c.Lock()
defer c.Unlock() 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) c.memCache.SetChunk(fileId, data)
if len(c.diskCaches) == 0 { if len(c.diskCaches) == 0 {

Loading…
Cancel
Save