Add cache ttl

This commit is contained in:
Asim
2016-05-03 19:26:50 +01:00
parent e541d45f38
commit b13361d010
2 changed files with 125 additions and 36 deletions

20
selector/cache/options.go vendored Normal file
View File

@@ -0,0 +1,20 @@
package cache
import (
"time"
"github.com/micro/go-micro/selector"
"golang.org/x/net/context"
)
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)
}
}