Skip to content

Conversation

@mingrammer
Copy link

Sometimes, we can run an operation that takes longer than the timeout of the incoming request. In this case, the whole request should be canceled along with all subtasks including the cache operations. But current implementation doesn't support passing context, so we can't cancel the cache operations even if the current context is expired.

So I added the passing context feature for all cache operations with this PR. It keeps the backward compatibility, thus does not affect existing code using gomemcache.

import (
    "github.com/bradfitz/gomemcache/memcache"
)
func main() {
    mc := memcache.New("10.0.0.1:11211", "10.0.0.2:11211", "10.0.0.3:11212")
    mc.Set(&memcache.Item{Key: "foo", Value: []byte("my value")})
    it, err := mc.Get("foo")

    // With context
    ctx, cancel := context.WithTimeout(2 * time.Second)
    doLongTimeJob(ctx)
    ...
    it, err = mc.GetWithContext(ctx, "bar")
    ...
}

I would appreciate it if you think about this feature in a good way.

@mingrammer mingrammer requested a review from hoonmin November 30, 2020 08:00
@mingrammer
Copy link
Author

upstream에도 일단 올려놨어요: bradfitz#126

Copy link

@hoonmin hoonmin left a comment

Choose a reason for hiding this comment

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

LGTM!

@hoonmin hoonmin merged commit fd50da2 into master Dec 8, 2020
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.

3 participants