MCPcopy
hub / github.com/kubernetes/client-go / getOrExpire

Method getOrExpire

tools/cache/expiration_cache.go:90–106  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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.
90func (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.
109func (c *ExpirationCache) GetByKey(key string) (interface{}, bool, error) {

Callers 3

GetByKeyMethod · 0.95
GetMethod · 0.95
ListMethod · 0.95

Calls 3

getTimestampedEntryMethod · 0.95
IsExpiredMethod · 0.65
DeleteMethod · 0.65

Tested by

no test coverage detected