Skip to content

fix: improve reliability of object cache management#63

Open
ermakov-oleg wants to merge 1 commit intooperasoftware:mainfrom
ermakov-oleg:fix/object-cache-bugs
Open

fix: improve reliability of object cache management#63
ermakov-oleg wants to merge 1 commit intooperasoftware:mainfrom
ermakov-oleg:fix/object-cache-bugs

Conversation

@ermakov-oleg
Copy link

Summary

Port of upstream #508, #429

Fixes 5 bugs in ExtendedClient cache that made caching completely non-functional:

  1. Wrong type assertion in isObjectCached: checked for *corev1.Secret instead of *pgbackrestv1.Archive, so Archive objects were never recognized as cacheable
  2. GVK comparison in getCachedObject: compared objects via GetObjectKind().GroupVersionKind() which returns empty GVK for decoded objects — replaced with reflect.TypeOf() comparison
  3. Inverted condition in removeObject: used != instead of == for GVK comparison, so cache invalidation never matched the right object — same fix with reflect.TypeOf()
  4. Missing TTL initialization: cachedEntry.ttl was never set, defaulting to 0 — every cached entry expired immediately on next access
  5. Incorrect unit comparison in isExpired(): time.Now().Unix() - fetchUnixTime returns seconds, but int64(ttl) yields nanoseconds — fixed with time.Since(time.Unix(fetchUnixTime, 0)) > ttl

Added 5 new unit tests (cache Archive objects, distinguish by type, removeObject matching, removeObject with shared keys, TTL initialization) and updated existing expired test to use real TTL.

Signed-off-by: ermakov-oleg <ermakovolegs@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant