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

Method gc

internal/storage/memory/memory.go:164–204  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

162}
163
164func (s *Storage) gc() {
165 // Close gcExited first so a panic in NewTicker (e.g. non-positive
166 // gcInterval) still unblocks Close.
167 defer close(s.gcExited)
168 ticker := time.NewTicker(s.gcInterval)
169 defer ticker.Stop()
170 var expired []string
171
172 for {
173 select {
174 case <-s.done:
175 return
176 case <-ticker.C:
177 ts := utils.Timestamp()
178 expired = expired[:0]
179 s.mux.RLock()
180 for id, v := range s.db {
181 if v.expiry != 0 && v.expiry < ts {
182 expired = append(expired, id)
183 }
184 }
185 s.mux.RUnlock()
186
187 if len(expired) == 0 {
188 // avoid locking if nothing to delete
189 continue
190 }
191
192 s.mux.Lock()
193 // Double-checked locking.
194 // We might have replaced the item in the meantime.
195 for i := range expired {
196 v := s.db[expired[i]]
197 if v.expiry != 0 && v.expiry <= ts {
198 delete(s.db, expired[i])
199 }
200 }
201 s.mux.Unlock()
202 }
203 }
204}
205
206// Conn returns the underlying storage map. The returned map remains shared with
207// the storage, so callers must not modify it and must synchronize any access

Callers 2

NewFunction · 0.95

Implementers 15

shutdownHookStorageservices_test.go
errorStorageshared_state_test.go
contextCheckingStorageshared_state_test.go
SharedStateshared_state.go
captureStoragectx_test.go
failingStoragectx_test.go
mutatingStoragemiddleware/cache/cache_test.go
failingCacheStoragemiddleware/cache/cache_test.go
failingCSRFStoragemiddleware/csrf/csrf_test.go
flakySessionStoragemiddleware/csrf/csrf_test.go
stubStoragemiddleware/idempotency/stub_test.go

Calls 2

LockMethod · 0.65
UnlockMethod · 0.65

Tested by 1