Open
Conversation
kiootic
reviewed
Jan 24, 2024
Comment on lines
+96
to
+97
| writer := httputil.NewTimeoutResponseWriter(w, 10*time.Second) | ||
| http.ServeContent(writer, r, path.Base(r.URL.Path), info.ModTime, cacheReader) |
Collaborator
There was a problem hiding this comment.
This logic is duplicated, please refactor.
internal/cache/contentcache.go
Outdated
| return &ContentCache{m: m, cache: cache}, nil | ||
| } | ||
|
|
||
| func (c *ContentCache) GetContent(id string, r io.Reader) (*bytes.Buffer, error) { |
Collaborator
There was a problem hiding this comment.
This signature is inappropiate, caches should return what is put in.
internal/cache/contentcache.go
Outdated
| func NewContentCache() (*ContentCache, error) { | ||
| m := make(map[string]*sync.Mutex) | ||
| cache, err := ristretto.NewCache(&ristretto.Config{ | ||
| NumCounters: 1e7, |
Collaborator
There was a problem hiding this comment.
How is this number derived?
internal/cache/contentcache.go
Outdated
| m := make(map[string]*sync.Mutex) | ||
| cache, err := ristretto.NewCache(&ristretto.Config{ | ||
| NumCounters: 1e7, | ||
| MaxCost: contentCacheSize, |
Collaborator
There was a problem hiding this comment.
This should be passed in as argument.
internal/cache/contentcache.go
Outdated
| BufferItems: 64, | ||
| OnExit: func(item interface{}) { | ||
| cell := item.(contentCacheCell) | ||
| delete(m, cell.hash) |
Collaborator
There was a problem hiding this comment.
Access to this map should be synchronized.
Collaborator
|
Please write a test for the ContentCache:
|
Instead of storing key and value as value, use a reference-counted map of rwmutexes (it automatically deletes mutexes so no need onExit in Ristretto) Separated into getContent and setContent in order to allow getContent call without io.ReadSeeker Used generics
b74cf6c to
9c1086c
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.