refactor(config): use generic cache for SegmentWriter#7316
refactor(config): use generic cache for SegmentWriter#7316Mertozturkk wants to merge 3 commits intoJanDeDobbeleer:mainfrom
Conversation
There was a problem hiding this comment.
Pull request overview
Refactors segment caching in config.Segment to store and restore SegmentWriter values directly via the generic cache API (instead of JSON serialization), while attempting to migrate legacy string cache entries.
Changes:
- Switch segment cache storage from
json.Marshal/json.Unmarshaltocache.Set/cache.Get[SegmentWriter]. - Add legacy-cache detection that deletes string cache entries so they can be regenerated.
- Add a unit test covering writer restoration and legacy-entry deletion.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| src/config/segment.go | Updates segment cache restore/set logic to use typed cache storage and adds legacy string cleanup. |
| src/config/segment_cache_test.go | Adds a unit test for segment cache restore and legacy key removal. |
be3e849 to
e04dca6
Compare
6a67260 to
85091a8
Compare
| } | ||
|
|
||
| // Never cache pending state to avoid polluting cache with incomplete data | ||
| if segment.Pending { |
There was a problem hiding this comment.
That check was accidentally removed during the refactor. I've restored it to ensure we don't pollute the cache with incomplete data when a segment is still in a pending state. Re-pushed the fix
143fef6 to
a520b40
Compare
a520b40 to
59f231b
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.
Comments suppressed due to low confidence (1)
src/config/segment.go:377
- Segment cache entries now store gob-encoded []byte under the existing "segment_cache_%s" keys. This changes the value type in-place, which can make troubleshooting/downgrades noisier (older versions expecting a JSON string will see a type mismatch/unmarshal failure in debug logs and won’t self-heal). Consider versioning/namespacing the cache key (e.g., "segment_cache_v2_%s") so different on-disk formats can coexist and upgrades/downgrades degrade to a cache miss instead of repeated decode errors.
func (segment *Segment) cacheKeyAndStore() (string, cache.Store) {
format := "segment_cache_%s"
switch segment.Cache.Strategy {
case Session:
return fmt.Sprintf(format, segment.Name()), cache.Session
case Device:
return fmt.Sprintf(format, segment.Name()), cache.Device
case Folder:
fallthrough
default:
return fmt.Sprintf(format, strings.Join([]string{segment.Name(), segment.folderKey()}, "_")), cache.Device
}
You can also share your feedback on Copilot code review. Take the survey.
Add iso8601 and iso8601ms styles for execution time display using ISO 8601 duration format (PT[n]H[n]M[n]S). The iso8601 style rounds to nearest second, while iso8601ms preserves milliseconds precision. Co-authored-by: Claude <noreply@anthropic.com>
|
@Mertozturkk this breaks when in streaming mode, didn't look at the details just yet but I can make the prompt fail now. I pushed the udpated branch, maybe I missed something silly. |
a97bf15 to
b1f5d4f
Compare
Prerequisites
Description
Refactored the segment caching mechanism to use generic types instead of JSON serialization, resolving the TODO in
setCache.Changes:
json.Marshal/json.Unmarshalwithcache.Get[SegmentWriter]andcache.Setfor direct interface storageTestSegmentCacheunit test covering both generic cache and legacy data migrationdefer cache.DeleteAllto prevent test state leakage