mirror of
https://github.com/TecharoHQ/anubis.git
synced 2026-04-16 21:34:59 +00:00
feat(decaymap): add Delete method
Signed-off-by: Xe Iaso <me@xeiaso.net>
This commit is contained in:
@@ -48,6 +48,26 @@ func (m *Impl[K, V]) expire(key K) bool {
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Delete a value from the DecayMap by key.
|
||||||
|
//
|
||||||
|
// If the value does not exist, return false. Otherwise return true after
|
||||||
|
// deletion.
|
||||||
|
func (m *Impl[K, V]) Delete(key K) bool {
|
||||||
|
m.lock.RLock()
|
||||||
|
_, ok := m.data[key]
|
||||||
|
m.lock.RUnlock()
|
||||||
|
|
||||||
|
if !ok {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
m.lock.Unlock()
|
||||||
|
delete(m.data, key)
|
||||||
|
m.lock.Lock()
|
||||||
|
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
// Get gets a value from the DecayMap by key.
|
// Get gets a value from the DecayMap by key.
|
||||||
//
|
//
|
||||||
// If a value has expired, forcibly delete it if it was not updated.
|
// If a value has expired, forcibly delete it if it was not updated.
|
||||||
|
|||||||
Reference in New Issue
Block a user