getOrExpire retrieves the object from the TimestampedEntry if and only if it hasn't already expired. It holds a write lock across deletion.
(key string)
| 88 | // getOrExpire retrieves the object from the TimestampedEntry if and only if it hasn't |
| 89 | // already expired. It holds a write lock across deletion. |
| 90 | func (c *ExpirationCache) getOrExpire(key string) (interface{}, bool) { |
| 91 | // Prevent all inserts from the time we deem an item as "expired" to when we |
| 92 | // delete it, so an un-expired item doesn't sneak in under the same key, just |
| 93 | // before the Delete. |
| 94 | c.expirationLock.Lock() |
| 95 | defer c.expirationLock.Unlock() |
| 96 | timestampedItem, exists := c.getTimestampedEntry(key) |
| 97 | if !exists { |
| 98 | return nil, false |
| 99 | } |
| 100 | if c.expirationPolicy.IsExpired(timestampedItem) { |
| 101 | klog.V(4).Infof("Entry %v: %+v has expired", key, timestampedItem.Obj) |
| 102 | c.cacheStorage.Delete(key) |
| 103 | return nil, false |
| 104 | } |
| 105 | return timestampedItem.Obj, true |
| 106 | } |
| 107 | |
| 108 | // GetByKey returns the item stored under the key, or sets exists=false. |
| 109 | func (c *ExpirationCache) GetByKey(key string) (interface{}, bool, error) { |