mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2024-01-19 02:48:24 +00:00
avoid duplicated setting chunks into cache
This commit is contained in:
parent
b9b7da905e
commit
2a1f396df5
|
@ -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 {
|
||||
|
|
Loading…
Reference in a new issue