|
|
@ -33,7 +33,7 @@ func NewChunkCache(maxEntries int64, dir string, diskSizeMB int64) *ChunkCache { |
|
|
|
return c |
|
|
|
} |
|
|
|
|
|
|
|
func (c *ChunkCache) GetChunk(fileId string, chunkSize uint64) (data []byte) { |
|
|
|
func (c *ChunkCache) GetChunk(fileId string, minSize uint64) (data []byte) { |
|
|
|
if c == nil { |
|
|
|
return |
|
|
|
} |
|
|
@ -41,14 +41,14 @@ func (c *ChunkCache) GetChunk(fileId string, chunkSize uint64) (data []byte) { |
|
|
|
c.RLock() |
|
|
|
defer c.RUnlock() |
|
|
|
|
|
|
|
return c.doGetChunk(fileId, chunkSize) |
|
|
|
return c.doGetChunk(fileId, minSize) |
|
|
|
} |
|
|
|
|
|
|
|
func (c *ChunkCache) doGetChunk(fileId string, chunkSize uint64) (data []byte) { |
|
|
|
func (c *ChunkCache) doGetChunk(fileId string, minSize uint64) (data []byte) { |
|
|
|
|
|
|
|
if chunkSize < memCacheSizeLimit { |
|
|
|
if minSize < memCacheSizeLimit { |
|
|
|
data = c.memCache.GetChunk(fileId) |
|
|
|
if len(data) >= int(chunkSize) { |
|
|
|
if len(data) >= int(minSize) { |
|
|
|
return data |
|
|
|
} |
|
|
|
} |
|
|
@ -59,21 +59,21 @@ func (c *ChunkCache) doGetChunk(fileId string, chunkSize uint64) (data []byte) { |
|
|
|
return nil |
|
|
|
} |
|
|
|
|
|
|
|
if chunkSize < onDiskCacheSizeLimit0 { |
|
|
|
if minSize < onDiskCacheSizeLimit0 { |
|
|
|
data = c.diskCaches[0].getChunk(fid.Key) |
|
|
|
if len(data) >= int(chunkSize) { |
|
|
|
if len(data) >= int(minSize) { |
|
|
|
return data |
|
|
|
} |
|
|
|
} |
|
|
|
if chunkSize < onDiskCacheSizeLimit1 { |
|
|
|
if minSize < onDiskCacheSizeLimit1 { |
|
|
|
data = c.diskCaches[1].getChunk(fid.Key) |
|
|
|
if len(data) >= int(chunkSize) { |
|
|
|
if len(data) >= int(minSize) { |
|
|
|
return data |
|
|
|
} |
|
|
|
} |
|
|
|
{ |
|
|
|
data = c.diskCaches[2].getChunk(fid.Key) |
|
|
|
if len(data) >= int(chunkSize) { |
|
|
|
if len(data) >= int(minSize) { |
|
|
|
return data |
|
|
|
} |
|
|
|
} |
|
|
|