make reader_at handle random reads more efficiently for FUSE
This commit is contained in:
@@ -31,6 +31,20 @@ func (c *ChunkCacheInMemory) GetChunk(fileId string) []byte {
|
||||
return data
|
||||
}
|
||||
|
||||
func (c *ChunkCacheInMemory) getChunkSlice(fileId string, offset, length uint64) ([]byte, error) {
|
||||
item := c.cache.Get(fileId)
|
||||
if item == nil {
|
||||
return nil, nil
|
||||
}
|
||||
data := item.Value().([]byte)
|
||||
item.Extend(time.Hour)
|
||||
wanted := min(int(length), len(data)-int(offset))
|
||||
if wanted < 0 {
|
||||
return nil, ErrorOutOfBounds
|
||||
}
|
||||
return data[offset : int(offset)+wanted], nil
|
||||
}
|
||||
|
||||
func (c *ChunkCacheInMemory) SetChunk(fileId string, data []byte) {
|
||||
localCopy := make([]byte, len(data))
|
||||
copy(localCopy, data)
|
||||
|
||||
Reference in New Issue
Block a user