您可以推荐什么JavaScript缓存 [英] What JavaScript cache can you recommend
本文介绍了您可以推荐什么JavaScript缓存的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在寻找一个好的Java脚本内存缓存库来缓存客户端计算结果.
i'm searching for a good java script in-memory cache lib to cache client side calculation results.
我的要求:
- 可在Internet Explorer,FireFox,Safari,Opera,Chrome和其他功能中使用
- 稳定
- 成熟
- 小
- 快速
- 缓存策略应该是可配置的
- 一页中的多个缓存,每个缓存具有不同的退出策略
- LFU,LRU加
您在网络项目中使用哪个?您可以推荐哪一个?
which one do you use in your web project? which one can you recommend?
推荐答案
看一下:
- jsCache :一个简单的LRU缓存.
- 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...
这篇关于您可以推荐什么JavaScript缓存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文