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

Method ttl

segment.go:321–347  ·  view source on GitHub ↗
(key []byte, hashVal uint64)

Source from the content-addressed store, hash-verified

319}
320
321func (seg *segment) ttl(key []byte, hashVal uint64) (timeLeft uint32, err error) {
322 slotId := uint8(hashVal >> 8)
323 hash16 := uint16(hashVal >> 16)
324 slot := seg.getSlot(slotId)
325 idx, match := seg.lookup(slot, hash16, key)
326 if !match {
327 err = ErrNotFound
328 return
329 }
330 ptr := &slot[idx]
331
332 var hdrBuf [ENTRY_HDR_SIZE]byte
333 seg.rb.ReadAt(hdrBuf[:], ptr.offset)
334 hdr := (*entryHdr)(unsafe.Pointer(&hdrBuf[0]))
335
336 if hdr.expireAt == 0 {
337 return
338 } else {
339 now := seg.timer.Now()
340 if !isExpired(hdr.expireAt, now) {
341 timeLeft = hdr.expireAt - now
342 return
343 }
344 }
345 err = ErrNotFound
346 return
347}
348
349func (seg *segment) expand() {
350 newSlotData := make([]entryPtr, seg.slotCap*2*256)

Callers 1

TTLMethod · 0.80

Calls 5

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

Tested by

no test coverage detected