What JavaScript cache can you recommend [closed]

核能气质少年 提交于 2020-01-04 04:56:10

问题


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?


回答1:


Give a look to:

  • jsCache: a simple LRU cache.

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...




回答2:


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.



来源:https://stackoverflow.com/questions/1322694/what-javascript-cache-can-you-recommend

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!