introduce service registry cache
This commit is contained in:
2 files changed
+12
-1
No files matched your search
@@ -0,0 +1,7 @@
|
|||||||
|
Enhancement: Introduce service registry cache
|
||||||
|
|
||||||
|
We've improved the service registry / service discovery by
|
||||||
|
setting up registry caching (TTL 20s), so that not every requests
|
||||||
|
has to do a lookup on the registry.
|
||||||
|
|
||||||
|
https://github.com/owncloud/ocis/pull/3833
|
||||||
@@ -3,6 +3,7 @@ package registry
|
|||||||
import (
|
import (
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
consulr "github.com/go-micro/plugins/v4/registry/consul"
|
consulr "github.com/go-micro/plugins/v4/registry/consul"
|
||||||
etcdr "github.com/go-micro/plugins/v4/registry/etcd"
|
etcdr "github.com/go-micro/plugins/v4/registry/etcd"
|
||||||
@@ -11,6 +12,7 @@ import (
|
|||||||
natsr "github.com/go-micro/plugins/v4/registry/nats"
|
natsr "github.com/go-micro/plugins/v4/registry/nats"
|
||||||
|
|
||||||
"go-micro.dev/v4/registry"
|
"go-micro.dev/v4/registry"
|
||||||
|
"go-micro.dev/v4/registry/cache"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@@ -46,5 +48,7 @@ func GetRegistry() registry.Registry {
|
|||||||
r = mdnsr.NewRegistry()
|
r = mdnsr.NewRegistry()
|
||||||
}
|
}
|
||||||
|
|
||||||
return r
|
// always use cached registry to prevent registry
|
||||||
|
// lookup for every request
|
||||||
|
return cache.New(r, cache.WithTTL(20*time.Second))
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user