Skip to content

Commit 31c7be0

Browse files
committed
'Inline' Get and Expired
1 parent 4e0d34e commit 31c7be0

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

cache.go

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,11 @@ func (item Item) expired(now time.Time) bool {
2626

2727
// Returns true if the item has expired.
2828
func (item Item) Expired() bool {
29-
return item.expired(time.Now())
29+
// "Inlining" of expired
30+
if item.Expiration == emptyTime {
31+
return false
32+
}
33+
return item.Expiration.Before(time.Now())
3034
}
3135

3236
const (
@@ -108,9 +112,14 @@ func (c *cache) Replace(k string, x interface{}, d time.Duration) error {
108112
// whether the key was found.
109113
func (c *cache) Get(k string) (interface{}, bool) {
110114
c.mu.RLock()
111-
x, found := c.get(k)
115+
// "Inlining" of get
116+
item, found := c.items[k]
117+
if !found || item.Expired() {
118+
c.mu.RUnlock()
119+
return nil, false
120+
}
112121
c.mu.RUnlock()
113-
return x, found
122+
return item.Object, found
114123
}
115124

116125
func (c *cache) get(k string) (interface{}, bool) {

0 commit comments

Comments
 (0)