aboutsummaryrefslogtreecommitdiff
path: root/internal/cache/clock/shard_read.go
blob: 624e34095be4c749438669d30a732a36aff84dee (about) (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
package clock

// get returns the value for key and marks it referenced.
//
//nolint:ireturn
func (shard *shard[K, V]) get(key K) (V, bool) {
	e, ok := shard.items.Load(key)
	if !ok {
		var zero V

		return zero, false
	}

	if !e.referenced.Load() {
		e.referenced.Store(true)
	}

	return e.value, true
}

// peek returns the value for key without affecting eviction.
//
//nolint:ireturn
func (shard *shard[K, V]) peek(key K) (V, bool) {
	e, ok := shard.items.Load(key)
	if !ok {
		var zero V

		return zero, false
	}

	return e.value, true
}