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

Can you update key? #57

Open
kingcw opened this issue Mar 16, 2023 · 1 comment
Open

Can you update key? #57

kingcw opened this issue Mar 16, 2023 · 1 comment

Comments

@kingcw
Copy link

kingcw commented Mar 16, 2023

Can you update a key's value directly? Or have to delete the key first, then set "key: new value"?

@sabouaram
Copy link

// Check if the key exists in the cache var value []byte err = h.Group.Get(nil, k, groupcache.AllocatingByteSliceSink(&value)) if err == nil { // Key exists in the cache, compare with the new value if !reflect.DeepEqual(value, v) { // Values are different, update the cache jsonValue, err := json.Marshal(v) if err != nil { return err } expireTime := time.Now().Add(time.Duration(h.cacheTTL) * time.Minute) err = h.Group.Set(context.Background(), k, jsonValue, expireTime, false) if err != nil { return err } } }

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

No branches or pull requests

2 participants