activated url caching.
--- a/src/js/data.js Tue Nov 15 16:34:38 2011 +0100
+++ b/src/js/data.js Tue Nov 15 16:54:09 2011 +0100
@@ -4,20 +4,23 @@
this._cache = {};
};
-IriSP.DataLoader.prototype.get = function(url, callback) {
+IriSP.DataLoader.prototype.get = function(url, callback) {
+
+ var base_url = url.split("&")[0]
if (this._cache.hasOwnProperty(url)) {
- callback(this._cache[url]);
+ callback(this._cache[base_url]);
} else {
/* we need a closure because this gets lost when it's called back */
- IriSP.jQuery.get(url, callback);
- /*
+ // uncomment you don't want to use caching.
+ // IriSP.jQuery.get(url, callback);
+
IriSP.jQuery.get(url, (function(obj) {
return function(data) {
- obj._cache[url] = data;
- callback(obj._cache[url]);
+ obj._cache[base_url] = data;
+ callback(obj._cache[base_url]);
};
})(this));
- */
+
}
}
--- a/unittests/tests/dataloader.js Tue Nov 15 16:34:38 2011 +0100
+++ b/unittests/tests/dataloader.js Tue Nov 15 16:54:09 2011 +0100
@@ -24,7 +24,7 @@
var spy_callback = this.spy();
var dt = new IriSP.DataLoader();
- var resp = dt.get("/url", spy_callback);
+ var resp = dt.get("/url&a=1", spy_callback);
equals(xhr.requests.length, 1, "the mock ajax object should have received the request");
@@ -35,8 +35,11 @@
ok(spy_callback.calledOnce, "callback called");
ok(spy_callback.calledWith(response_array), "callback called with correct string");
- // FIXME : remove or activate this test.
- //deepEqual(dt._cache["/url"], response_array, "the response should be stored in the cache");
+ deepEqual(dt._cache["/url"], response_array, "the response should be stored in the cache");
+
+ var resp2 = dt.get("/url&a=2", spy_callback);
+ ok(spy_callback.calledOnce, "callback called only once");
+
});
}
\ No newline at end of file