Skip to content

feat: implement LRU TTL refresh for S3 cache on Open#173

Merged
worstell merged 2 commits intomainfrom
s3-lru-ttl
Mar 12, 2026
Merged

feat: implement LRU TTL refresh for S3 cache on Open#173
worstell merged 2 commits intomainfrom
s3-lru-ttl

Conversation

@worstell
Copy link
Copy Markdown
Contributor

Problem

S3 cache entries expire based on creation time (fixed TTL). Frequently accessed snapshots expire after 72h regardless of usage, causing cold cache misses after pod restarts when no periodic jobs are running to refresh them.

Solution

Like the disk cache, S3 now resets the expiration time on each Open using a server-side copy-to-self with metadata replacement (CopyObject with ReplaceMetadata). No data is re-uploaded — only the Expires-At user metadata is updated.

Content freshness is still handled by periodic generateAndUploadSnapshot jobs (every 1h) which overwrite the S3 entry with a fresh snapshot from the latest git state.

@worstell worstell requested a review from a team as a code owner March 11, 2026 01:48
@worstell worstell requested review from stuartwdouglas and removed request for a team March 11, 2026 01:48
Copy link
Copy Markdown
Collaborator

@alecthomas alecthomas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Glorious!

Comment thread internal/cache/s3.go
}

// refreshExpiration updates the Expires-At metadata on an S3 object using
// server-side copy-to-self with metadata replacement. This avoids re-uploading
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this fast?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

going to spin it off into an async routine so it doesnt block. it will also only trigger when we're 50% of the way or more towards the TTL

worstell and others added 2 commits March 12, 2026 14:12
Like the disk cache, S3 now resets the expiration time on each Open
(read) using server-side copy-to-self with metadata replacement. This
prevents frequently accessed snapshots from expiring while periodic
snapshot jobs handle content freshness.

Co-authored-by: Amp <amp@ampcode.com>
Amp-Thread-ID: https://ampcode.com/threads/T-019cda52-ee36-738c-86cd-1fd410c47d7f
@worstell worstell enabled auto-merge (squash) March 12, 2026 21:12
@worstell worstell merged commit 6314159 into main Mar 12, 2026
6 checks passed
@worstell worstell deleted the s3-lru-ttl branch March 12, 2026 21:13
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.

2 participants