From b596d1d506ebe56e8c5dc46317f9141174b7191a Mon Sep 17 00:00:00 2001 From: Willy Kloucek Date: Thu, 19 May 2022 09:54:00 +0200 Subject: [PATCH] introduce service registry cache --- changelog/unreleased/enhancement-registry-cache.md | 7 +++++++ ocis-pkg/registry/registry.go | 6 +++++- 2 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 changelog/unreleased/enhancement-registry-cache.md diff --git a/changelog/unreleased/enhancement-registry-cache.md b/changelog/unreleased/enhancement-registry-cache.md new file mode 100644 index 000000000..c3aeb2382 --- /dev/null +++ b/changelog/unreleased/enhancement-registry-cache.md @@ -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 diff --git a/ocis-pkg/registry/registry.go b/ocis-pkg/registry/registry.go index 05c5998ca..fcee90921 100644 --- a/ocis-pkg/registry/registry.go +++ b/ocis-pkg/registry/registry.go @@ -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" @@ -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 ( @@ -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)) }