Skip to content

Commit

Permalink
'Inline' Get and Expired
Browse files Browse the repository at this point in the history
  • Loading branch information
patrickmn committed Nov 30, 2015
1 parent 4e0d34e commit 31c7be0
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,11 @@ func (item Item) expired(now time.Time) bool {

// Returns true if the item has expired.
func (item Item) Expired() bool {
return item.expired(time.Now())
// "Inlining" of expired
if item.Expiration == emptyTime {
return false
}
return item.Expiration.Before(time.Now())
}

const (
Expand Down Expand Up @@ -108,9 +112,14 @@ func (c *cache) Replace(k string, x interface{}, d time.Duration) error {
// whether the key was found.
func (c *cache) Get(k string) (interface{}, bool) {
c.mu.RLock()
x, found := c.get(k)
// "Inlining" of get
item, found := c.items[k]
if !found || item.Expired() {
c.mu.RUnlock()
return nil, false
}
c.mu.RUnlock()
return x, found
return item.Object, found
}

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

0 comments on commit 31c7be0

Please sign in to comment.