Cost vs value and limiting memory consumption

I have some values I want to cache which are very expensive to generate in terms of processing, and some that are comparatively cheaper but have a bigger size in bytes.

As I understand it I can input the cost of generating each item in the Set() method to prioritize keeping expensive items in the cache. However I also want to limit the size of the cache to about 100MB, so if I use the time complexity as the cost value, the MaxCost parameter doesn’t limit the space taken up by the cache.

Is there or will there be a concept of “worth” vs “storage cost”? Let’s say some values are expensive but tiny, and others are cheap to generate but take up a lot of space. The small values should almost never be evicted, and almost always be admitted into the cache. Can these two concepts be captured in Ristretto? As I understand it I would want to specify the storage cost of a value separately from the cost of generating the value, and have a separate parameter for the max memory footprint, separate from the current MaxCost parameter?

Hey @hkeide,
While passing the cost of generating each item in the Set() to prioritize, you can consider multiplying the cost of generating with the size of an element. I think you’ll be able to consider both of the factors from this.

Tagging @ashishgoswami for confirmation and more details.

Hi, that’s a great idea. I guess since “size” is a negative thing, and “value” is a positive thing with regards to keeping the value in the cache, I would have to use division rather than multiplication, but the concept is the same. I then wonder if a higher “cost” value leads to greater or lesser retention. Since it seems the original concept of “cost” is primarily intended to be used for entry size I’m guessing an entry with a higher cost will be evicted sooner?