freecache icon indicating copy to clipboard operation
freecache copied to clipboard

Why we couldn't set Key-Value larger than 1/1024 of cache size?

Open Prots opened this issue 8 years ago • 10 comments

Is it possible to make this stuff configurable?

Prots avatar Nov 23 '17 15:11 Prots

It's limited by the data structure, large values don't fit in the data structure.

coocood avatar Nov 23 '17 18:11 coocood

Out of curiosity — I get why it can't be larger than 1/256 (separate segments), but where does the extra factor of 4 come from? Is it primarily just to avoid wasting space if your entries take up too big a fraction of a segment, or is there some other reason that that factor must be of 4?

glasser avatar Apr 02 '18 18:04 glasser

@glasser If an entry takes too big a fraction of a segment, it will be evicted when a new entry is written, the LRU algorithm does not work.

coocood avatar Apr 03 '18 01:04 coocood

@coocood Hi, also experiencing this issue, trying to set the value to something thats big enough! Can you kindly advise what unit of measurement this variable is in. Seems like I experience this error with almost every byte object i try to store unless I follow your documentation on the README. Which is great, but I don't know which numbers represent what!

caldempsey avatar Mar 13 '20 15:03 caldempsey

@mmacheerpuppy The code is at this line https://github.com/coocood/freecache/blob/master/segment.go#L85 It's not configurable.

coocood avatar Mar 14 '20 10:03 coocood

@coocood Sorry to add confusion, I mean these values cache := freecache.NewCache( 100 * 1024 * 1024), not sure why we do 100 * 1024 * 1024!

caldempsey avatar Mar 17 '20 12:03 caldempsey

@coocood Sorry to add confusion, I mean these values cache := freecache.NewCache( 100 * 1024 * 1024), not sure why we do 100 * 1024 * 1024!

I'm sorry for misunderstanding your question. The unit is byte, 1024 * 1024 means MB, I think it is the default unit for memory size if not specified.

coocood avatar Mar 17 '20 14:03 coocood

@coocood Right okay that makes total sense to me now, could I open a PR to get that in the README? (See PRs!)

caldempsey avatar Mar 17 '20 20:03 caldempsey

@mmacheerpuppy Sure!

coocood avatar Mar 18 '20 04:03 coocood