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

Skip key generation if cache disabled #170

Merged
merged 1 commit into from
Apr 19, 2024
Merged
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
30 changes: 17 additions & 13 deletions pkg/stores/partition/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,18 +175,22 @@ func (s *Store) List(apiOp *types.APIRequest, schema *types.APISchema) (types.AP

opts := listprocessor.ParseQuery(apiOp)

key, err := s.getCacheKey(apiOp, opts)
if err != nil {
return result, err
}

var list []unstructured.Unstructured
if key.revision != "" && s.listCache != nil {
cachedList, ok := s.listCache.Get(key)
if ok {
logrus.Tracef("found cached list for query %s?%s", apiOp.Request.URL.Path, apiOp.Request.URL.RawQuery)
list = cachedList.(*unstructured.UnstructuredList).Items
result.Continue = cachedList.(*unstructured.UnstructuredList).GetContinue()
var key cacheKey
if s.listCache != nil {
key, err = s.getCacheKey(apiOp, opts)
if err != nil {
return result, err
}

if key.revision != "" {
cachedList, ok := s.listCache.Get(key)
if ok {
logrus.Tracef("found cached list for query %s?%s", apiOp.Request.URL.Path, apiOp.Request.URL.RawQuery)
list = cachedList.(*unstructured.UnstructuredList).Items
result.Continue = cachedList.(*unstructured.UnstructuredList).GetContinue()
result.Revision = key.revision
}
}
}
if list == nil { // did not look in cache or was not found in cache
Expand All @@ -202,7 +206,7 @@ func (s *Store) List(apiOp *types.APIRequest, schema *types.APISchema) (types.AP
return result, lister.Err()
}
list = listprocessor.SortList(list, opts.Sort)
key.revision = lister.Revision()
result.Revision = lister.Revision()
listToCache := &unstructured.UnstructuredList{
Items: list,
}
Expand All @@ -212,6 +216,7 @@ func (s *Store) List(apiOp *types.APIRequest, schema *types.APISchema) (types.AP
listToCache.SetContinue(c)
}
if s.listCache != nil {
key.revision = result.Revision
s.listCache.Add(key, listToCache, 30*time.Minute)
}
result.Continue = lister.Continue()
Expand All @@ -224,7 +229,6 @@ func (s *Store) List(apiOp *types.APIRequest, schema *types.APISchema) (types.AP
result.Objects = append(result.Objects, toAPI(schema, item, nil))
}

result.Revision = key.revision
result.Pages = pages
return result, lister.Err()
}
Expand Down