Peek returns the key value (or undefined if not found) without updating the "recently used"-ness of the key.
(key K)
| 171 | // Peek returns the key value (or undefined if not found) without updating |
| 172 | // the "recently used"-ness of the key. |
| 173 | func (c *LRU[K, V]) Peek(key K) (value V, ok bool) { |
| 174 | c.mu.RLock() |
| 175 | defer c.mu.RUnlock() |
| 176 | var ent *Entry[K, V] |
| 177 | if ent, ok = c.items[key]; ok { |
| 178 | // Expired item check |
| 179 | if time.Now().After(ent.ExpiresAt) { |
| 180 | return value, false |
| 181 | } |
| 182 | return ent.Value, true |
| 183 | } |
| 184 | return |
| 185 | } |
| 186 | |
| 187 | // Remove removes the provided key from the cache, returning if the |
| 188 | // key was contained. |