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

Method locate

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

Source from the content-addressed store, hash-verified

274}
275
276func (seg *segment) locate(key []byte, hashVal uint64, peek bool) (hdrEntry entryHdr, ptrOffset int64, err error) {
277 slotId := uint8(hashVal >> 8)
278 hash16 := uint16(hashVal >> 16)
279 slot := seg.getSlot(slotId)
280 idx, match := seg.lookup(slot, hash16, key)
281 if !match {
282 err = ErrNotFound
283 if !peek {
284 atomic.AddInt64(&seg.missCount, 1)
285 }
286 return
287 }
288 ptr := &slot[idx]
289
290 var hdrBuf [ENTRY_HDR_SIZE]byte
291 seg.rb.ReadAt(hdrBuf[:], ptr.offset)
292 hdr := (*entryHdr)(unsafe.Pointer(&hdrBuf[0]))
293 if !peek {
294 now := seg.timer.Now()
295 if isExpired(hdr.expireAt, now) {
296 seg.delEntryPtr(slotId, slot, idx)
297 atomic.AddInt64(&seg.totalExpired, 1)
298 err = ErrNotFound
299 atomic.AddInt64(&seg.missCount, 1)
300 return
301 }
302 atomic.AddInt64(&seg.totalTime, int64(now-hdr.accessTime))
303 hdr.accessTime = now
304 seg.rb.WriteAt(hdrBuf[:], ptr.offset)
305 }
306 return *hdr, ptr.offset, nil
307}
308
309func (seg *segment) del(key []byte, hashVal uint64) (affected bool) {
310 slotId := uint8(hashVal >> 8)

Callers 2

getMethod · 0.95
viewMethod · 0.95

Calls 7

getSlotMethod · 0.95
lookupMethod · 0.95
delEntryPtrMethod · 0.95
isExpiredFunction · 0.85
ReadAtMethod · 0.80
WriteAtMethod · 0.80
NowMethod · 0.65

Tested by

no test coverage detected