The lru-cache code 
<https://github.com/isaacs/node-lru-cache/blob/master/lib/lru-cache.js> is 
pretty small and worth reading through if you're using any of the fancy 
options.  It looks like length calculation functions are passed the values 
(not keys, so, in your case, your documents, so you probably want it to 
return n.length or something).  Additionally "max" refers to the same units 
as you return from length(), so if your documents are 1.5kb your max needs 
to be something on the order of KBs or MBs.

If you know your average size, don't want specific size calculations going 
on, then just use the simple example, don't pass any options, just pass a 
max size (default length function already returns 1, so the max is just max 
number of elements).

And, reading the documentation on GitHub it appears to say almost exactly 
what I just said when describing the various options.

On Sunday, May 3, 2015 at 6:53:56 PM UTC-7, MC wrote:
>
> Hello,
> I'm looking for clarification on how to set cache max size. In this 
> example:
>
> var LRU = require("lru-cache")
>   , options = { max: 500
>               , length: function (n) { return n * 2 }
>               , dispose: function (key, n) { n.close() }
>               , maxAge: 1000 * 60 * 60 }
>   , cache = LRU(options)
>   , otherCache = LRU(50) // sets just the max size
>
>
> What value does 'length' function operate on? Is n related to key or value 
> stored in cache?
> I store documents of an average size of 1.5 kB in cache. Key is an MD5 
> hash (constant length).
> Since I know average document size can I return 1 as length function 
> output, and treat max as document count?
> I.e. if max = 500 then it's an indicator of 500 documents, each of size 
> 1.5 kB (750 kB total)?
> Thanks,
>
> M
>
>

-- 
Job board: http://jobs.nodejs.org/
New group rules: 
https://gist.github.com/othiym23/9886289#file-moderation-policy-md
Old group rules: 
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
--- 
You received this message because you are subscribed to the Google Groups 
"nodejs" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to nodejs+unsubscr...@googlegroups.com.
To post to this group, send email to nodejs@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/nodejs/f5ec658f-e705-43cc-8980-4dc3a74279c3%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to