MCPcopy
hub / github.com/gofiber/fiber / put

Method put

middleware/cache/heap.go:64–82  ·  view source on GitHub ↗

Returns index to track entry

(key string, exp uint64, bytes uint)

Source from the content-addressed store, hash-verified

62
63// Returns index to track entry
64func (h *indexedHeap) put(key string, exp uint64, bytes uint) int {
65 idx := 0
66 if len(h.entries) < h.maxidx {
67 // Steal index from previously removed entry
68 // capacity > size is guaranteed
69 n := len(h.entries)
70 idx = h.entries[:n+1][n].idx
71 } else {
72 idx = h.maxidx
73 h.maxidx++
74 h.indices = append(h.indices, idx)
75 }
76 // Push manually to avoid allocation
77 h.pushInternal(heapEntry{
78 key: key, exp: exp, idx: idx, bytes: bytes,
79 })
80 heap.Fix(h, h.Len()-1)
81 return idx
82}
83
84func (h *indexedHeap) removeInternal(realIdx int) (key string, size uint) { //nolint:nonamedreturns // gocritic unnamedResult prefers named key and size when removing heap entries
85 x := heap.Remove(h, realIdx).(heapEntry) //nolint:forcetypeassert,errcheck // Forced type assertion required to implement the heap.Interface interface

Callers 2

NewFunction · 0.95

Calls 2

pushInternalMethod · 0.95
LenMethod · 0.95

Tested by 1