Skip to content
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support passing context #1

Merged
merged 1 commit into from
Dec 8, 2020
Merged

feat: support passing context #1

merged 1 commit into from
Dec 8, 2020

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
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.

2 participants