aboutsummaryrefslogtreecommitdiffstats
path: root/dashboard/app/cache.go
diff options
context:
space:
mode:
authorAleksandr Nogikh <nogikh@google.com>2023-10-25 15:32:15 +0200
committerTaras Madan <tarasmadan@google.com>2023-10-25 13:57:32 +0000
commit72e794c46fcfe059006cd6efdf2f6f315a71ff56 (patch)
tree1706ce350770aeae4f3940d9384698d7220c1876 /dashboard/app/cache.go
parent17e6d52686f8a56935991f1b066798279f76504a (diff)
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.
Diffstat (limited to 'dashboard/app/cache.go')
-rw-r--r--dashboard/app/cache.go28
1 files changed, 28 insertions, 0 deletions
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
+}