2016-05-03 19:26:50 +01:00
|
|
|
package cache
|
|
|
|
|
|
|
|
import (
|
2018-03-03 11:53:52 +00:00
|
|
|
"context"
|
2016-05-03 19:26:50 +01:00
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/micro/go-micro/selector"
|
|
|
|
)
|
|
|
|
|
|
|
|
type ttlKey struct{}
|
|
|
|
|
|
|
|
// Set the cache ttl
|
|
|
|
func TTL(t time.Duration) selector.Option {
|
|
|
|
return func(o *selector.Options) {
|
|
|
|
if o.Context == nil {
|
|
|
|
o.Context = context.Background()
|
|
|
|
}
|
|
|
|
o.Context = context.WithValue(o.Context, ttlKey{}, t)
|
|
|
|
}
|
|
|
|
}
|