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

just curious over SetBig #16

Closed
hiqsociety opened this issue Jun 9, 2019 · 2 comments
Closed

just curious over SetBig #16

hiqsociety opened this issue Jun 9, 2019 · 2 comments
Labels
question Further information is requested

Comments

@hiqsociety
Copy link

hiqsociety commented Jun 9, 2019

Why not add SetBig here,

if len(k) >= (1<<16) || len(v) >= (1<<16) {
              SetBig(k,v) //what's wrong with adding here and needing to do a new SetBig?
    }

Because I don't know if my cache value will exceed 64kb so I'll do :

if len(k) >= (1<<16) || len(v) >= (1<<16) {
               fastcache.SetBig(k,v)
     }else{
               fastcache.Set(k,v)
     }

Any problems with the above? With reference to function below:

   func (b *bucket) Set(k, v []byte, h uint64) {
setCalls := atomic.AddUint64(&b.setCalls, 1)
if setCalls%(1<<14) == 0 {
	b.Clean()
}

if len(k) >= (1<<16) || len(v) >= (1<<16) {
	// Too big key or value - its length cannot be encoded
	// with 2 bytes (see below). Skip the entry.
	return
}
@valyala valyala added the question Further information is requested label Jun 9, 2019
@valyala
Copy link
Collaborator

valyala commented Jun 9, 2019

Values stored with SetBig must be read with GetBig. They cannot be read with Get. See docs for details.
So stick to SetBig / GetBig if you are unsure if value sizes may exceed 64KB. These functions work with smaller values too.

@hiqsociety
Copy link
Author

Right. I forgot. Thanks I got it now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants