Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

introduce service registry cache #3833

Merged
merged 1 commit into from
May 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions changelog/unreleased/enhancement-registry-cache.md
Original file line number Diff line number Diff line change
@@ -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
6 changes: 5 additions & 1 deletion ocis-pkg/registry/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package registry
import (
"os"
"strings"
"time"

consulr "github.com/go-micro/plugins/v4/registry/consul"
etcdr "github.com/go-micro/plugins/v4/registry/etcd"
Expand All @@ -11,6 +12,7 @@ import (
natsr "github.com/go-micro/plugins/v4/registry/nats"

"go-micro.dev/v4/registry"
"go-micro.dev/v4/registry/cache"
)

var (
Expand Down Expand Up @@ -46,5 +48,7 @@ func GetRegistry() registry.Registry {
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))
}