[PR #2564] [MERGED] fix: use type-safe keyvalue caching to fix Redis avatar/preview cache #5733

Closed
opened 2026-04-16 13:50:40 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/go-vikunja/vikunja/pull/2564
Author: @tink-bot
Created: 4/8/2026
Status: Merged
Merged: 4/8/2026
Merged by: @kolaente

Base: mainHead: fix-avatar-cache-redis


📝 Commits (4)

  • feeba8d feat: add generic RememberValue[T] for type-safe keyvalue caching
  • cf7172b fix: register gob types and use RememberValue for avatar and unsplash cache
  • 9284655 fix: use RememberValue for task attachment preview cache
  • 1d2d0ef test: remove obsolete invalid-cache-type test for avatar upload

📊 Changes

5 files changed (+51 additions, -68 deletions)

View changed files

📝 pkg/models/task_attachment.go (+2 -2)
📝 pkg/modules/avatar/upload/upload.go (+15 -38)
📝 pkg/modules/avatar/upload/upload_test.go (+0 -25)
📝 pkg/modules/background/unsplash/unsplash.go (+6 -3)
📝 pkg/modules/keyvalue/keyvalue.go (+28 -0)

📄 Description

The Remember() function in the keyvalue package uses Get() to check the cache, but the Redis implementation of Get() returns a raw string without gob-decoding. Since Put() gob-encodes non-integer values, the returned string can never be type-asserted back to the original struct type (e.g. CachedAvatar, Photo, []byte). This causes avatar caching, unsplash photo caching, and task attachment preview caching to break completely when Redis is used as the keyvalue backend.

This adds a generic RememberValue[T]() function that uses GetWithValue() internally for proper gob-deserialization, and migrates all three affected callers to use it.

Fixes https://github.com/go-vikunja/vikunja/issues/2217


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/go-vikunja/vikunja/pull/2564 **Author:** [@tink-bot](https://github.com/tink-bot) **Created:** 4/8/2026 **Status:** ✅ Merged **Merged:** 4/8/2026 **Merged by:** [@kolaente](https://github.com/kolaente) **Base:** `main` ← **Head:** `fix-avatar-cache-redis` --- ### 📝 Commits (4) - [`feeba8d`](https://github.com/go-vikunja/vikunja/commit/feeba8d8f1e21923a5b4a778fd279a430e1233a1) feat: add generic RememberValue[T] for type-safe keyvalue caching - [`cf7172b`](https://github.com/go-vikunja/vikunja/commit/cf7172bb22c9e7e9028f6a392cfd875dd54004da) fix: register gob types and use RememberValue for avatar and unsplash cache - [`9284655`](https://github.com/go-vikunja/vikunja/commit/92846555b378ab0db9895f1f8ec50f300db76348) fix: use RememberValue for task attachment preview cache - [`1d2d0ef`](https://github.com/go-vikunja/vikunja/commit/1d2d0ef9aacc239c9edb09b7795165d2d6463883) test: remove obsolete invalid-cache-type test for avatar upload ### 📊 Changes **5 files changed** (+51 additions, -68 deletions) <details> <summary>View changed files</summary> 📝 `pkg/models/task_attachment.go` (+2 -2) 📝 `pkg/modules/avatar/upload/upload.go` (+15 -38) 📝 `pkg/modules/avatar/upload/upload_test.go` (+0 -25) 📝 `pkg/modules/background/unsplash/unsplash.go` (+6 -3) 📝 `pkg/modules/keyvalue/keyvalue.go` (+28 -0) </details> ### 📄 Description The `Remember()` function in the keyvalue package uses `Get()` to check the cache, but the Redis implementation of `Get()` returns a raw string without gob-decoding. Since `Put()` gob-encodes non-integer values, the returned string can never be type-asserted back to the original struct type (e.g. `CachedAvatar`, `Photo`, `[]byte`). This causes avatar caching, unsplash photo caching, and task attachment preview caching to break completely when Redis is used as the keyvalue backend. This adds a generic `RememberValue[T]()` function that uses `GetWithValue()` internally for proper gob-deserialization, and migrates all three affected callers to use it. Fixes https://github.com/go-vikunja/vikunja/issues/2217 --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
GiteaMirror added the pull-request label 2026-04-16 13:50:40 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/vikunja#5733