i'm searching for a good java script in-memory cache lib to cache client side calculation results.
My requirements:
which one do you use in your web project? which one can you recommend?
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...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With