From 72e794c46fcfe059006cd6efdf2f6f315a71ff56 Mon Sep 17 00:00:00 2001 From: Aleksandr Nogikh Date: Wed, 25 Oct 2023 15:32:15 +0200 Subject: dashboard: cache per-ns manager lists The query may take up to 100ms in some cases, while the result changes on quite rare occasions. Let's use a cached version of the data when rendering UI pages. We don't need extra tests because it's already excercised in existing tests that trigger web endpoints. --- dashboard/app/cache.go | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'dashboard/app/cache.go') diff --git a/dashboard/app/cache.go b/dashboard/app/cache.go index 4e77d55cf..f52cf5d11 100644 --- a/dashboard/app/cache.go +++ b/dashboard/app/cache.go @@ -206,3 +206,31 @@ func minuteCacheNsUpdate(c context.Context, ns string) error { } return nil } + +func CachedManagerList(c context.Context, ns string) ([]string, error) { + key := fmt.Sprintf("%s-managers-list", ns) + + // Check if the object is in cache. + list := []string{} + _, err := memcache.Gob.Get(c, key, &list) + if err == nil { + return list, nil + } else if err != memcache.ErrCacheMiss { + return nil, err + } + + // Update cache. + list, err = managerList(c, ns) + if err != nil { + return nil, err + } + item := &memcache.Item{ + Key: key, + Object: list, + Expiration: time.Minute, + } + if err := memcache.Gob.Set(c, item); err != nil { + return nil, err + } + return list, nil +} -- cgit mrf-deployment