# HG changeset patch # User hamidouk # Date 1321372449 -3600 # Node ID 69bc26f879e6712bd51cfea550f3696b1a00b142 # Parent 533716922da56204808eb3c349477c2afaec0b0a activated url caching. diff -r 533716922da5 -r 69bc26f879e6 src/js/data.js --- 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)); - */ + } } diff -r 533716922da5 -r 69bc26f879e6 unittests/tests/dataloader.js --- 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