FAQ
https://github.com/medikoo/memoize

npm install memoizee

For one of my projects I needed memoizer, that would be both fast and would
work with any type of input arguments. Other projects demanded other common
functionalities, so it's result of real world needs I approached in last
months. To make it complete in latest stage I added max and maxAge options
(lru-cache inspiration)

Features in short:
- Works with any type of function arguments – no serialization is needed
- Works with any length of function arguments. Length can be set as fixed
or dynamic.
- One of the fastest available solutions (when talking about plain simple
case it's slightly slower than basic underscore implementation and about 3
x faster than lru-cache)
- Support for asynchronous functions
- Optional primitive mode which assures fast performance when arguments are
conversible to strings.
- Can be configured for methods (when `this` counts in)
- Cache can be cleared manually or after specified timeout
- Cache size can be limited
- Optionally accepts resolvers that normalize function arguments before
passing them to underlying function.
- Optional reference counter mode, that allows more sophisticated cache
management
- Profile tool that provides valuable usage statistics
- Covered by over 500 unit tests

I use it all over the place now. Let me know what you think, any feedback
highly welcome

--
Job Board: http://jobs.nodejs.org/
Posting guidelines: 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 post to this group, send email to nodejs@googlegroups.com
To unsubscribe from this group, send email to
nodejs+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en

Search Discussions

  • Jeff Barczewski at Sep 19, 2012 at 3:15 pm
    Mariusz,

    memoize looks really nice! I am going to try it out for some projects I am
    working on.

    As for suggestions:

    - you might consider wrapping the file in a function closure so it can be
    used directly in a browser
    - could you add a LRU option? (I know you have many other algorithms, but
    would be nice to have if it doesn't add too much bulk)

    Thanks for sharing this!

    All the best,

    Jeff

    --
    Job Board: http://jobs.nodejs.org/
    Posting guidelines: 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 post to this group, send email to nodejs@googlegroups.com
    To unsubscribe from this group, send email to
    nodejs+unsubscribe@googlegroups.com
    For more options, visit this group at
    http://groups.google.com/group/nodejs?hl=en?hl=en
  • Jeff Barczewski at Sep 19, 2012 at 3:18 pm
    Mariusz,

    I took a closer look and realized that there a many dependencies (I was
    thinking it was self contained), so not as simple to get into the browser,
    either need to use something like AMD or build a distribution file with one
    of the commonsjs browser build solutions.

    Jeff


    On Wednesday, 19 September 2012 10:14:57 UTC-5, Jeff Barczewski wrote:

    Mariusz,

    memoize looks really nice! I am going to try it out for some projects I am
    working on.

    As for suggestions:

    - you might consider wrapping the file in a function closure so it can be
    used directly in a browser
    - could you add a LRU option? (I know you have many other algorithms, but
    would be nice to have if it doesn't add too much bulk)

    Thanks for sharing this!

    All the best,

    Jeff
    --
    Job Board: http://jobs.nodejs.org/
    Posting guidelines: 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 post to this group, send email to nodejs@googlegroups.com
    To unsubscribe from this group, send email to
    nodejs+unsubscribe@googlegroups.com
    For more options, visit this group at
    http://groups.google.com/group/nodejs?hl=en?hl=en
  • Mariusz Nowak at Sep 19, 2012 at 3:52 pm
    Jeff,

    It can easily be ported to browser with help of
    Webmake https://github.com/medikoo/modules-webmake (it's mentioned in
    documentation)
    Anyway to make it even easier I prepared a bundle ->
    https://github.com/medikoo/memoize/downloads ;)

    According to LRU option, you can achieve it with 'max' option ->
    https://github.com/medikoo/memoize#limiting-cache-size
    See also 'maxAge' and 'dispose' options. Is that what you're after?

    On Wednesday, September 19, 2012 5:17:58 PM UTC+2, Jeff Barczewski wrote:

    Mariusz,

    I took a closer look and realized that there a many dependencies (I was
    thinking it was self contained), so not as simple to get into the browser,
    either need to use something like AMD or build a distribution file with one
    of the commonsjs browser build solutions.

    Jeff


    On Wednesday, 19 September 2012 10:14:57 UTC-5, Jeff Barczewski wrote:

    Mariusz,

    memoize looks really nice! I am going to try it out for some projects I
    am working on.

    As for suggestions:

    - you might consider wrapping the file in a function closure so it can
    be used directly in a browser
    - could you add a LRU option? (I know you have many other algorithms,
    but would be nice to have if it doesn't add too much bulk)

    Thanks for sharing this!

    All the best,

    Jeff
    --
    Job Board: http://jobs.nodejs.org/
    Posting guidelines: 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 post to this group, send email to nodejs@googlegroups.com
    To unsubscribe from this group, send email to
    nodejs+unsubscribe@googlegroups.com
    For more options, visit this group at
    http://groups.google.com/group/nodejs?hl=en?hl=en
  • Jeff Barczewski at Sep 19, 2012 at 7:36 pm
    Mariusz,

    You are right, I missed the mention in the readme about building it for the
    browser, but it is nice that you prepared a download bundle. Honestly I
    just went right to the code first and only glanced at the README for the
    API, so I ended up missing that.

    Correct me if I am wrong, but isn't the max option, FIFO, so unlike a LRU
    cache which keeps the most recently used objects cached, this would expire
    the first one that was cached regardless of whether it was recently
    used/requested or not.

    One reason this is nice is that a LRU cache ends up staying loaded with the
    most popular content, the random requests don't end up kicking out an
    important one.

    For many things, the max option would be fine, but just for completeness
    (and a very popular use case), it would be great to have a LRU option.

    Just my thoughts for completing out the feature set. I think your project
    is great none the less.

    Jeff


    On Wednesday, 19 September 2012 10:47:07 UTC-5, Mariusz Nowak wrote:

    Jeff,

    It can easily be ported to browser with help of Webmake
    https://github.com/medikoo/modules-webmake (it's mentioned in
    documentation)
    Anyway to make it even easier I prepared a bundle ->
    https://github.com/medikoo/memoize/downloads ;)

    According to LRU option, you can achieve it with 'max' option ->
    https://github.com/medikoo/memoize#limiting-cache-size
    See also 'maxAge' and 'dispose' options. Is that what you're after?

    On Wednesday, September 19, 2012 5:17:58 PM UTC+2, Jeff Barczewski wrote:

    Mariusz,

    I took a closer look and realized that there a many dependencies (I was
    thinking it was self contained), so not as simple to get into the browser,
    either need to use something like AMD or build a distribution file with one
    of the commonsjs browser build solutions.

    Jeff


    On Wednesday, 19 September 2012 10:14:57 UTC-5, Jeff Barczewski wrote:

    Mariusz,

    memoize looks really nice! I am going to try it out for some projects I
    am working on.

    As for suggestions:

    - you might consider wrapping the file in a function closure so it can
    be used directly in a browser
    - could you add a LRU option? (I know you have many other algorithms,
    but would be nice to have if it doesn't add too much bulk)

    Thanks for sharing this!

    All the best,

    Jeff
    --
    Job Board: http://jobs.nodejs.org/
    Posting guidelines: 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 post to this group, send email to nodejs@googlegroups.com
    To unsubscribe from this group, send email to
    nodejs+unsubscribe@googlegroups.com
    For more options, visit this group at
    http://groups.google.com/group/nodejs?hl=en?hl=en
  • Mariusz Nowak at Sep 21, 2012 at 1:32 pm
    Jeff, sorry for delayed response, I wanted to take some time and look into
    LRU case. Indeed it's much more useful approach than FIFO, I changed
    internal algorithm for max option to use that
    instead: https://github.com/medikoo/memoize/blob/master/lib/ext/max.js so
    now it's definitely backed by LRU.

    I've also improved modularization, so other algorithms if needed can be
    easily configured. New browser bundle can be found in downloads section, if
    you want you can (using webmake) create bundle trimmed of functionalities
    you don't need - see lib/index.js how it's done, one that I've uploaded
    provides everything.

    Mariusz
    On Wednesday, September 19, 2012 9:36:38 PM UTC+2, Jeff Barczewski wrote:

    Mariusz,

    You are right, I missed the mention in the readme about building it for
    the browser, but it is nice that you prepared a download bundle. Honestly I
    just went right to the code first and only glanced at the README for the
    API, so I ended up missing that.

    Correct me if I am wrong, but isn't the max option, FIFO, so unlike a LRU
    cache which keeps the most recently used objects cached, this would expire
    the first one that was cached regardless of whether it was recently
    used/requested or not.

    One reason this is nice is that a LRU cache ends up staying loaded with
    the most popular content, the random requests don't end up kicking out an
    important one.

    For many things, the max option would be fine, but just for completeness
    (and a very popular use case), it would be great to have a LRU option.

    Just my thoughts for completing out the feature set. I think your project
    is great none the less.

    Jeff


    On Wednesday, 19 September 2012 10:47:07 UTC-5, Mariusz Nowak wrote:

    Jeff,

    It can easily be ported to browser with help of Webmake
    https://github.com/medikoo/modules-webmake (it's mentioned in
    documentation)
    Anyway to make it even easier I prepared a bundle ->
    https://github.com/medikoo/memoize/downloads ;)

    According to LRU option, you can achieve it with 'max' option ->
    https://github.com/medikoo/memoize#limiting-cache-size
    See also 'maxAge' and 'dispose' options. Is that what you're after?

    On Wednesday, September 19, 2012 5:17:58 PM UTC+2, Jeff Barczewski wrote:

    Mariusz,

    I took a closer look and realized that there a many dependencies (I was
    thinking it was self contained), so not as simple to get into the browser,
    either need to use something like AMD or build a distribution file with one
    of the commonsjs browser build solutions.

    Jeff


    On Wednesday, 19 September 2012 10:14:57 UTC-5, Jeff Barczewski wrote:

    Mariusz,

    memoize looks really nice! I am going to try it out for some projects I
    am working on.

    As for suggestions:

    - you might consider wrapping the file in a function closure so it can
    be used directly in a browser
    - could you add a LRU option? (I know you have many other algorithms,
    but would be nice to have if it doesn't add too much bulk)

    Thanks for sharing this!

    All the best,

    Jeff
    --
    Job Board: http://jobs.nodejs.org/
    Posting guidelines: 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 post to this group, send email to nodejs@googlegroups.com
    To unsubscribe from this group, send email to
    nodejs+unsubscribe@googlegroups.com
    For more options, visit this group at
    http://groups.google.com/group/nodejs?hl=en?hl=en
  • Jeff Barczewski at Oct 1, 2012 at 5:32 pm
    Excellent! Thanks for all your work on this!

    --
    Job Board: http://jobs.nodejs.org/
    Posting guidelines: 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 post to this group, send email to nodejs@googlegroups.com
    To unsubscribe from this group, send email to
    nodejs+unsubscribe@googlegroups.com
    For more options, visit this group at
    http://groups.google.com/group/nodejs?hl=en?hl=en
  • Vitaly Puzrin at Sep 23, 2012 at 10:45 pm
    Mariusz,

    Thanks for sharing memoizee.

    I have comment about timeouts. Very often, it's recommended to use
    "replace" strategy, instead of "delete". I mean,
    if data is expired, you still continue to return old data from cache, but
    fetch new one in background. It can be easily implemented
    in async mode. That has 2 benefits:
    - no freezes on expires
    - easy to avoid parallel refresh requests

    Vitaly.

    среда, 19 сентября 2012 г., 2:06:21 UTC+4 пользователь Mariusz Nowak
    написал:
    https://github.com/medikoo/memoize

    npm install memoizee

    For one of my projects I needed memoizer, that would be both fast and
    would work with any type of input arguments. Other projects demanded other
    common functionalities, so it's result of real world needs I approached in
    last months. To make it complete in latest stage I added max and maxAge
    options (lru-cache inspiration)

    Features in short:
    - Works with any type of function arguments - no serialization is needed
    - Works with any length of function arguments. Length can be set as fixed
    or dynamic.
    - One of the fastest available solutions (when talking about plain simple
    case it's slightly slower than basic underscore implementation and about 3
    x faster than lru-cache)
    - Support for asynchronous functions
    - Optional primitive mode which assures fast performance when arguments
    are conversible to strings.
    - Can be configured for methods (when `this` counts in)
    - Cache can be cleared manually or after specified timeout
    - Cache size can be limited
    - Optionally accepts resolvers that normalize function arguments before
    passing them to underlying function.
    - Optional reference counter mode, that allows more sophisticated cache
    management
    - Profile tool that provides valuable usage statistics
    - Covered by over 500 unit tests

    I use it all over the place now. Let me know what you think, any feedback
    highly welcome
    --
    Job Board: http://jobs.nodejs.org/
    Posting guidelines: 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 post to this group, send email to nodejs@googlegroups.com
    To unsubscribe from this group, send email to
    nodejs+unsubscribe@googlegroups.com
    For more options, visit this group at
    http://groups.google.com/group/nodejs?hl=en?hl=en
  • Mariusz Nowak at Sep 24, 2012 at 12:08 pm
    Vitaly,

    Most cases I've approached with memoize was to provide value *on demand*,
    so not to generate additional work if there's no need to. If it expires
    it's vanished, maybe it won't be needed again, leave it the way it is.
    Anyway I can imagine cases where behavior you describe can be desirable, so
    it`s probably worthwhile extension (and quite easy to add), I've added
    issue https://github.com/medikoo/memoize/issues/1, so it'll soon be
    possible. Thanks! :)
    On Monday, September 24, 2012 12:45:48 AM UTC+2, Vitaly Puzrin wrote:

    Mariusz,

    Thanks for sharing memoizee.

    I have comment about timeouts. Very often, it's recommended to use
    "replace" strategy, instead of "delete". I mean,
    if data is expired, you still continue to return old data from cache, but
    fetch new one in background. It can be easily implemented
    in async mode. That has 2 benefits:
    - no freezes on expires
    - easy to avoid parallel refresh requests

    Vitaly.

    среда, 19 сентября 2012 г., 2:06:21 UTC+4 пользователь Mariusz Nowak
    написал:
    https://github.com/medikoo/memoize

    npm install memoizee

    For one of my projects I needed memoizer, that would be both fast and
    would work with any type of input arguments. Other projects demanded other
    common functionalities, so it's result of real world needs I approached in
    last months. To make it complete in latest stage I added max and maxAge
    options (lru-cache inspiration)

    Features in short:
    - Works with any type of function arguments - no serialization is needed
    - Works with any length of function arguments. Length can be set as fixed
    or dynamic.
    - One of the fastest available solutions (when talking about plain simple
    case it's slightly slower than basic underscore implementation and about 3
    x faster than lru-cache)
    - Support for asynchronous functions
    - Optional primitive mode which assures fast performance when arguments
    are conversible to strings.
    - Can be configured for methods (when `this` counts in)
    - Cache can be cleared manually or after specified timeout
    - Cache size can be limited
    - Optionally accepts resolvers that normalize function arguments before
    passing them to underlying function.
    - Optional reference counter mode, that allows more sophisticated cache
    management
    - Profile tool that provides valuable usage statistics
    - Covered by over 500 unit tests

    I use it all over the place now. Let me know what you think, any feedback
    highly welcome
    --
    Job Board: http://jobs.nodejs.org/
    Posting guidelines: 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 post to this group, send email to nodejs@googlegroups.com
    To unsubscribe from this group, send email to
    nodejs+unsubscribe@googlegroups.com
    For more options, visit this group at
    http://groups.google.com/group/nodejs?hl=en?hl=en

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupnodejs @
categoriesnodejs
postedSep 18, '12 at 10:06p
activeOct 1, '12 at 5:32p
posts9
users3
websitenodejs.org
irc#node.js

People

Translate

site design / logo © 2022 Grokbase