String.prototype.format = function(){
    var str = this;
    for (var i = 0; i < arguments.length; i++) {
        var re = new RegExp('\\{' + (i) + '\\}', 'gm');
        str = str.replace(re, arguments[i]);
    }
    return str;
};
var ajaxHelper = function(){
		
	var _postCache = {};
	var _postQueue = {};
	
	return {
		post: function( url, data, callback, type, o ){
			o = $.extend({
				life: 60 * 30 // default is 30 min
			}, o);
			if ( $.isFunction( data ) ) {
				type = callback;// fix the bug in $.post
				callback = data;
				data = {};
			}
			var key = '{0},{1},{2}'.format(url, type, $.param(data));
			var now = +new Date;
			var item = _postCache[key];
			if( item && now-item.birthday<o.life*1000 )
			{
				callback(item.data);
			}
			else
			{
				if( _postQueue[key] && _postQueue[key].length>0 ){
					_postQueue[key].push(callback);
				}
				else
				{
					_postQueue[key] = [callback];
					$.post(url, data, function(data){
						_postCache[key] = {birthday:now, data:data};
						var queue = _postQueue[key], f;
						while( f=queue.shift() )
							f(data);
					}, type);
				}
			}
		}
	};
}();