Skip to content

Commit 1add4dc

Browse files
authored
Add warning that Peek functions return expired values (#133)
1 parent 64a2e40 commit 1add4dc

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

cache.go

+5-1
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,8 @@ func (cache *Cache) Update(key []byte, updater Updater) (found bool, replaced bo
165165
}
166166

167167
// Peek returns the value or not found error, without updating access time or counters.
168+
// Warning: No expiry check is performed so if an expired value is found, it will be
169+
// returned without error
168170
func (cache *Cache) Peek(key []byte) (value []byte, err error) {
169171
hashVal := hashFunc(key)
170172
segID := hashVal & segmentAndOpVal
@@ -178,11 +180,13 @@ func (cache *Cache) Peek(key []byte) (value []byte, err error) {
178180
// provided function with slice view over the current underlying value of the
179181
// key in memory. The slice is constrained in length and capacity.
180182
//
181-
// In moth cases, this method will not alloc a byte buffer. The only exception
183+
// In most cases, this method will not alloc a byte buffer. The only exception
182184
// is when the value wraps around the underlying segment ring buffer.
183185
//
184186
// The method will return ErrNotFound is there's a miss, and the function will
185187
// not be called. Errors returned by the function will be propagated.
188+
// Warning: No expiry check is performed so if an expired value is found, it will be
189+
// returned without error
186190
func (cache *Cache) PeekFn(key []byte, fn func([]byte) error) (err error) {
187191
hashVal := hashFunc(key)
188192
segID := hashVal & segmentAndOpVal

0 commit comments

Comments
 (0)