Skip to content

Commit e7a9def

Browse files
committed
Add SetDefault() for setting with the default expiration
1 parent 5258177 commit e7a9def

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

cache.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,12 @@ func (c *cache) set(k string, x interface{}, d time.Duration) {
8181
}
8282
}
8383

84+
// Add an item to the cache, replacing any existing item, using the default
85+
// expiration.
86+
func (c *cache) SetDefault(k string, x interface{}) {
87+
c.Set(k, x, DefaultExpiration)
88+
}
89+
8490
// Add an item to the cache only if an item doesn't already exist for the given
8591
// key, or if the existing item has expired. Returns an error otherwise.
8692
func (c *cache) Add(k string, x interface{}, d time.Duration) error {

0 commit comments

Comments
 (0)