aboutsummaryrefslogtreecommitdiff
path: root/internal/lru/get.go
blob: 92196003d16eafe6bad2472af35afe7f5e502ba3 (about) (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
package lru

// Get returns value for key and marks it most-recently-used.
func (cache *Cache[K, V]) Get(key K) (V, bool) {
	elem, ok := cache.items[key]
	if !ok {
		var zero V

		return zero, false
	}

	cache.lru.MoveToBack(elem)
	//nolint:forcetypeassert
	return elem.Value.(*entry[K, V]).value, true
}