diff options
| author | chrislu <chris.lu@gmail.com> | 2022-02-25 21:55:04 -0800 |
|---|---|---|
| committer | chrislu <chris.lu@gmail.com> | 2022-02-25 21:55:04 -0800 |
| commit | 3ad5fa6f6f513df152ff155b1fdd93a3c411b6ca (patch) | |
| tree | f8547d0111603a2765c0179a0f00c1817a0ea9f9 /weed/util/chunk_cache/chunk_cache_in_memory.go | |
| parent | fc7a4957eae6a3f58fb52c88210019e4af89a290 (diff) | |
| download | seaweedfs-3ad5fa6f6f513df152ff155b1fdd93a3c411b6ca.tar.xz seaweedfs-3ad5fa6f6f513df152ff155b1fdd93a3c411b6ca.zip | |
chunk cache adds function ReadChunkAt
Diffstat (limited to 'weed/util/chunk_cache/chunk_cache_in_memory.go')
| -rw-r--r-- | weed/util/chunk_cache/chunk_cache_in_memory.go | 18 |
1 files changed, 16 insertions, 2 deletions
diff --git a/weed/util/chunk_cache/chunk_cache_in_memory.go b/weed/util/chunk_cache/chunk_cache_in_memory.go index d725f8a16..2982d0979 100644 --- a/weed/util/chunk_cache/chunk_cache_in_memory.go +++ b/weed/util/chunk_cache/chunk_cache_in_memory.go @@ -1,9 +1,8 @@ package chunk_cache import ( - "time" - "github.com/karlseguin/ccache/v2" + "time" ) // a global cache for recently accessed file chunks @@ -45,6 +44,21 @@ func (c *ChunkCacheInMemory) getChunkSlice(fileId string, offset, length uint64) return data[offset : int(offset)+wanted], nil } +func (c *ChunkCacheInMemory) readChunkAt(buffer []byte, fileId string, offset uint64) (int, error) { + item := c.cache.Get(fileId) + if item == nil { + return 0, nil + } + data := item.Value().([]byte) + item.Extend(time.Hour) + wanted := min(len(buffer), len(data)-int(offset)) + if wanted < 0 { + return 0, ErrorOutOfBounds + } + n := copy(buffer, data[offset:int(offset)+wanted]) + return n, nil +} + func (c *ChunkCacheInMemory) SetChunk(fileId string, data []byte) { localCopy := make([]byte, len(data)) copy(localCopy, data) |
