views:

187

answers:

2

i'm searching for a good java script in-memory cache lib to cache client side calculation results.

My requirements:

  • works in Internet Explorer, FireFox, Safari, Opera, Chrome, others a plus
  • stable
  • mature
  • small
  • fast
  • cache strategies should be configurable
  • several caches in one page, each with different eviciton strategy
  • LFU, LRU a plus

which one do you use in your web project? which one can you recommend?

+3  A: 

Give a look to:

It's very easy to implement a pattern of self-memorizing functions:

function isPrime( num ) {
  if ( isPrime.cache.getItem(num) != null ) // check if the result is already
    return isPrime.cache.getItem(num);      // cached

  var prime = num != 1; 
  for ( var i = 2; i < num; i++ ) {  // determine if the number is prime
    if ( num % i == 0 ) {
      prime = false;
      break;
    }
  }
  isPrime.cache.setItem(num, prime); // store the result on cache
  return prime;
}

isPrime.cache = new Cache();

//...

isPrime(5);  // true
isPrime.cache.getItem(5);  // true, the result has been cached

You are able to specify the expiration time (absolute or relative), the priority of an item, and a callback function that will be executed when the item is removed from the cache...

CMS
did u use it? or just a google hit?
Chris
yes, posted a basic function-memorization sample
CMS
+2  A: 

Well, it's still beta and i guess since it is very old it wont be developed further, but maybe your can give it a look:

JSOC Framework

it was developed by Webframeworks LLC. I once uesed it in a project and it did a very good job so i can recommend it.

ManBugra