Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

chore: file cache Release tied 1:1 with an acquire#18410

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
Emyrk merged 7 commits intomainfromstevenmasley/cache_releaseable
Jun 18, 2025

Conversation

Emyrk
Copy link
Member

Made idempotent

Copy link
MemberAuthor

@EmyrkEmyrk left a comment

Choose a reason for hiding this comment

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

It might be even more correct to have each file reference have someuuid. Then we can be sure Aquire to Release is 1:1.

I did not want to refactor too much right now, so kept the underlying release mechanism the same.

Comment on lines 150 to 156
type CloseFS struct {
fs.FS

close func() error
}

func (f *CloseFS) Close() error { return f.close() }
Copy link
MemberAuthor

Choose a reason for hiding this comment

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

I named thisClose to match the pattern of opening a file and deferring aClose

//
// release should only be called after a successful call to Acquire using the Release()
// method on the returned *CloseFS.
func (c *Cache) release(fileID uuid.UUID) {
Copy link
MemberAuthor

Choose a reason for hiding this comment

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

Unexported to force callers to use theClose method for releasing.

@EmyrkEmyrk marked this pull request as ready for reviewJune 17, 2025 21:27
@EmyrkEmyrk requested a review fromaslilacJune 17, 2025 21:27
returnnil,err
}

returnit.FS,err
varonce sync.Once
Copy link
Member

Choose a reason for hiding this comment

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

I'd rather store theOnce on thestruct and then just put the closing logic directly in theClose method.

Copy link
MemberAuthor

Choose a reason for hiding this comment

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

You also have to store thefiles.Cache on the struct then too.
Which allows callingAcquire and other methods.

It would be something like:

typeCloseFSstruct {fs.FSonce sync.OncefileID uuid.UUIDcache*Cache}func (f*CloseFS)Close()error {f.once.Do(func() {f.cache.release(f.fileID)})}

I do not wantcache to be accessible, so I could throw therelease as a method, but then we're back to having an anonymous function as a field. In that case, I'd rather not add fields to the struct that are only used inClose

@@ -206,7 +208,8 @@ func TestRelease(t *testing.T) {
for closedIdx, id := range ids {
stillOpen := len(ids) - closedIdx
for closingIdx := range batchSize {
c.Release(id)
_ = releases[id][0]()
releases[id] = releases[id][1:]
Copy link
Member

Choose a reason for hiding this comment

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

just change the loops to iterate over thisreleases map if you really wanna do it this way

Copy link
MemberAuthor

Choose a reason for hiding this comment

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

I didn't feel like changing the test. This works

@EmyrkEmyrk requested a review fromaslilacJune 18, 2025 19:45
@EmyrkEmyrk merged commit04d202a intomainJun 18, 2025
34 checks passed
@EmyrkEmyrk deleted the stevenmasley/cache_releaseable branchJune 18, 2025 23:22
@github-actionsgithub-actionsbot locked and limited conversation to collaboratorsJun 18, 2025
Sign up for freeto subscribe to this conversation on GitHub. Already have an account?Sign in.
Reviewers

@aslilacaslilacaslilac approved these changes

Assignees

@EmyrkEmyrk

Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

2 participants
@Emyrk@aslilac

[8]ページ先頭

©2009-2025 Movatter.jp