MCPcopy
hub / github.com/coocood/freecache / get

Method get

segment.go:238–255  ·  view source on GitHub ↗
(key, buf []byte, hashVal uint64, peek bool)

Source from the content-addressed store, hash-verified

236}
237
238func (seg *segment) get(key, buf []byte, hashVal uint64, peek bool) (value []byte, expireAt uint32, err error) {
239 hdr, ptrOffset, err := seg.locate(key, hashVal, peek)
240 if err != nil {
241 return
242 }
243 expireAt = hdr.expireAt
244 if cap(buf) >= int(hdr.valLen) {
245 value = buf[:hdr.valLen]
246 } else {
247 value = make([]byte, hdr.valLen)
248 }
249
250 seg.rb.ReadAt(value, ptrOffset+ENTRY_HDR_SIZE+int64(hdr.keyLen))
251 if !peek {
252 atomic.AddInt64(&seg.hitCount, 1)
253 }
254 return
255}
256
257// view provides zero-copy access to the element's value, without copying to
258// an intermediate buffer.

Callers 10

GetMethod · 0.80
MultiGetMethod · 0.80
GetOrSetMethod · 0.80
SetAndGetMethod · 0.80
UpdateMethod · 0.80
PeekMethod · 0.80
PeekWithExpirationMethod · 0.80
GetWithBufMethod · 0.80
GetWithExpirationMethod · 0.80

Calls 2

locateMethod · 0.95
ReadAtMethod · 0.80

Tested by

no test coverage detected