Chr*_*ris 3 javascript caching
我正在寻找一个好的java脚本内存缓存lib来缓存客户端计算结果.
我的要求:
您在Web项目中使用哪一个?你能推荐哪一个?
看看:
实现自记忆功能的模式非常容易:
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
Run Code Online (Sandbox Code Playgroud)
您可以指定到期时间(绝对或相对),项目的优先级以及从缓存中删除项目时将执行的回调函数...
| 归档时间: |
|
| 查看次数: |
1671 次 |
| 最近记录: |