Keys returns a slice of the keys in the cache, from oldest to newest. Expired entries are filtered out.
()
| 235 | // Keys returns a slice of the keys in the cache, from oldest to newest. |
| 236 | // Expired entries are filtered out. |
| 237 | func (c *LRU[K, V]) Keys() []K { |
| 238 | c.mu.RLock() |
| 239 | defer c.mu.RUnlock() |
| 240 | keys := make([]K, 0, len(c.items)) |
| 241 | now := time.Now() |
| 242 | for ent := c.evictList.Back(); ent != nil; ent = ent.PrevEntry() { |
| 243 | if now.After(ent.ExpiresAt) { |
| 244 | continue |
| 245 | } |
| 246 | keys = append(keys, ent.Key) |
| 247 | } |
| 248 | return keys |
| 249 | } |
| 250 | |
| 251 | // Values returns a slice of the values in the cache, from oldest to newest. |
| 252 | // Expired entries are filtered out. |