mirror of
https://github.com/go-micro/go-micro.git
synced 2025-07-06 22:35:51 +02:00
broker
client
cmd
codec
errors
examples
metadata
registry
selector
cache
cache.go
cache_test.go
options.go
default.go
default_test.go
doc.go
filter.go
filter_test.go
options.go
selector.go
strategy.go
strategy_test.go
server
transport
.travis.yml
LICENSE
README.md
go-micro.go
go-micro.png
options.go
service.go
wrapper.go
wrapper_test.go
21 lines
350 B
Go
21 lines
350 B
Go
![]() |
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)
|
||
|
}
|
||
|
}
|