2007-08-30

推荐一个Javascript LRU Cache 对象。

关键字: ajax javascript cache
http://www.monsur.com/projects/jscache/

这个js cache不错。 功能也比较全。在项目中用它来缓存些大计算量的javascript json 对象。


Cache cache = new Cache(200);

function reloadTagCloud() {
	if (startDate != null && endDate != null) {
		showIndicator();
		var result = null;
		if (tagSource == "Directory"){
			result = cache.getItem("Directory" + startDate + endDate);
		}
		if (result != null){
			processTagResult(result);
			hideIndicator();
			return ;
		}
		jsonrpc.subscribe.getTags(getTagsCallback, startDate, endDate, tagSource, 'frequency' /*tagOrder, should sort the top 20 locally, always use frequency on server side.*/);
	}
}

function getTagsCallback(result, exception) {
	if (exception) {
		showError("An error has occurred: " + exception.message);
	} else {
		if (tagSource == "Directory"){
			cache.setItem("Directory" + startDate + endDate, result);
		}
		processTagResult(result);
	}
	
	hideIndicator();
}

function processTagResult(result){
		tagCloud.viewTags = result.sort(sortByFrquency);

		tagCloud.setTagFontSizes();

		updatTagCloudViewByOrder();
		try {
			dojo.byId("tagsButton").focus();
		} catch (e) {}
}
评论
dengyin2000 2007-12-27
carrot 写道
good

carrot

your colleague


萝卜 你的处女贴献给了我呀。
afcn0 2007-12-26
这个cache什么东西,是不是就是对象数组还是个什么,没听说过
carrot 2007-12-26
good

carrot

your colleague
sp42 2007-09-01
往事如烟了 呵呵
只是当年的激情。。不知现在算不算在延续着...
借javaeye这一宝地...抒心中之一幕...见谅了
dengyin2000 2007-08-31
sp42 写道
Cache...这令我想起当年Cyrix 486DLC中那1kb的回写式缓存是多么的宝贵啊....


你那当年是什么年代。 我是没有经历过寸土寸斤的年代。 羡慕。
sp42 2007-08-30
Cache...这令我想起当年Cyrix 486DLC中那1kb的回写式缓存是多么的宝贵啊....
发表评论

提醒: 该博客已发表在公共论坛,博客所有留言会成为论坛回贴,留言请注意遵守论坛发贴规则

您还没有登录,请登录后发表评论

dengyin2000
搜索本博客
我的相册
4d063000-8eef-365d-8346-f210ccfd5265-thumb
VB-seamless
共 13 张
存档
最新评论