Get looks up a key's value from the cache.
(key K)
| 145 | |
| 146 | // Get looks up a key's value from the cache. |
| 147 | func (c *LRU[K, V]) Get(key K) (value V, ok bool) { |
| 148 | c.mu.Lock() |
| 149 | defer c.mu.Unlock() |
| 150 | var ent *Entry[K, V] |
| 151 | if ent, ok = c.items[key]; ok { |
| 152 | // Expired item check |
| 153 | if time.Now().After(ent.ExpiresAt) { |
| 154 | return value, false |
| 155 | } |
| 156 | c.evictList.MoveToFront(ent) |
| 157 | return ent.Value, true |
| 158 | } |
| 159 | return |
| 160 | } |
| 161 | |
| 162 | // Contains checks if a key is in the cache, without updating the recent-ness |
| 163 | // or deleting it for being stale. |
nothing calls this directly
no test coverage detected