From 86ccac8a97458a12d2c08aebd9381185f9d7e5ea Mon Sep 17 00:00:00 2001 From: joamag Date: Wed, 25 Jul 2018 17:34:18 +0100 Subject: [PATCH] new cached flag usage --- src/js/ripe-min.js | 2 +- src/js/ripe.js | 3 ++- src/python/ripe_demo/static/js/ripe.js | 3 ++- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/js/ripe-min.js b/src/js/ripe-min.js index 04ad72e3c..c9cdf4aef 100644 --- a/src/js/ripe-min.js +++ b/src/js/ripe-min.js @@ -40,7 +40,7 @@ var _target=event.target||event.srcElement;var rect=_target.getBoundingClientRec var objectS=JSON.stringify(object);return JSON.parse(objectS);};ripe.equal=function(first,second){if(first===second){return true;} var firstS=JSON.stringify(first);var secondS=JSON.stringify(second);return firstS===secondS;};if(typeof require!=="undefined"){var base=require("./base");var compat=require("./compat");require("./ripe");var ripe=base.ripe;var XMLHttpRequest=compat.XMLHttpRequest;} ripe.RipeAPI=function(options){return new ripe.Ripe(null,null,options);};ripe.Ripe.prototype.signin=function(username,password,options,callback){callback=typeof options==="function"?options:callback;options=typeof options==="function"?{}:options;var url=this.url+"signin";options=Object.assign(options,{url:url,method:"POST",params:{username:username,password:password}});options=this._build(options);return this._cacheURL(options.url,options,callback);};ripe.Ripe.prototype.getConfig=function(options,callback){callback=typeof options==="function"?options:callback;options=typeof options==="function"?{}:options;options=this._getConfigOptions(options);options=this._build(options);return this._cacheURL(options.url,options,callback);};ripe.Ripe.prototype.getPrice=function(options,callback){callback=typeof options==="function"?options:callback;options=typeof options==="function"?{}:options;options=this._getPriceOptions(options);options=this._build(options);return this._cacheURL(options.url,options,callback);};ripe.Ripe.prototype.getDefaults=function(options,callback){callback=typeof options==="function"?options:callback;options=typeof options==="function"?{}:options;options=this._getDefaultsOptions(options);options=this._build(options);return this._cacheURL(options.url,options,function(result,isValid,request){callback&&callback(isValid?result.parts:result,isValid,request);});};ripe.Ripe.prototype.getOptionals=function(options,callback){return this.getDefaults(options,function(defaults,isValid,request){var optionals=[];for(var name in defaults){var part=defaults[name];part.optional&&optionals.push(name);} -callback&&callback(optionals,isValid,request);});};ripe.Ripe.prototype.getCombinations=function(options,callback){callback=typeof options==="function"?options:callback;options=typeof options==="function"?{}:options;options=this._getCombinationsOptions(options);options=this._build(options);return this._cacheURL(options.url,options,function(result,isValid,request){callback&&callback(isValid?result.combinations:result,isValid,request);});};ripe.Ripe.prototype._cacheURL=function(url,options,callback){callback=typeof options==="function"?options:callback;options=typeof options==="function"?{}:options;var key=options.key||"default";var fullKey=key+":"+url;var cached=!options.force&&["GET"].indexOf(options.method||"GET")!==-1;this._cache=this._cache===undefined?{}:this._cache;if(this._cache[fullKey]!==undefined&&cached){callback&&callback(this._cache[fullKey],true,null);return null;} +callback&&callback(optionals,isValid,request);});};ripe.Ripe.prototype.getCombinations=function(options,callback){callback=typeof options==="function"?options:callback;options=typeof options==="function"?{}:options;options=this._getCombinationsOptions(options);options=this._build(options);return this._cacheURL(options.url,options,function(result,isValid,request){callback&&callback(isValid?result.combinations:result,isValid,request);});};ripe.Ripe.prototype._cacheURL=function(url,options,callback){callback=typeof options==="function"?options:callback;options=typeof options==="function"?{}:options;var key=options.key||"default";var fullKey=key+":"+url;var cached=typeof options.cached==="undefined"?true:options.cached;cached=cached&&!options.force&&["GET"].indexOf(options.method||"GET")!==-1;this._cache=this._cache===undefined?{}:this._cache;if(this._cache[fullKey]!==undefined&&cached){callback&&callback(this._cache[fullKey],true,null);return null;} return this._requestURL(url,options,function(result,isValid,request){if(isValid&&cached){this._cache[fullKey]=result;} callback&&callback(result,isValid,request);}.bind(this));};ripe.Ripe.prototype._requestURL=function(url,options,callback){callback=typeof options==="function"?options:callback;options=typeof options==="function"?{}:options;var context=this;var method=options.method||"GET";var params=options.params||{};var headers=options.headers||{};var data=options.data||null;var contentType=options.contentType||null;var query=this._buildQuery(params);var isEmpty=["GET","DELETE"].indexOf(method)!==-1;var hasQuery=url.indexOf("?")!==-1;var separator=hasQuery?"&":"?";if(isEmpty||data){url+=separator+query;}else{data=query;contentType="application/x-www-form-urlencoded";} var request=new XMLHttpRequest();request.addEventListener("load",function(){var result=null;var isValid=this.status===200;try{result=JSON.parse(this.responseText);}catch(error){} diff --git a/src/js/ripe.js b/src/js/ripe.js index 0c336f15e..ce651215c 100644 --- a/src/js/ripe.js +++ b/src/js/ripe.js @@ -844,7 +844,8 @@ ripe.Ripe.prototype._cacheURL = function(url, options, callback) { // determines if the current request should be cached, obeys // some of the basic rules for that behaviour - var cached = !options.force && ["GET"].indexOf(options.method || "GET") !== -1; + var cached = typeof options.cached === "undefined" ? true : options.cached; + cached = cached && !options.force && ["GET"].indexOf(options.method || "GET") !== -1; // initializes the cache object in the current instance // in case it does not exists already diff --git a/src/python/ripe_demo/static/js/ripe.js b/src/python/ripe_demo/static/js/ripe.js index 0c336f15e..ce651215c 100644 --- a/src/python/ripe_demo/static/js/ripe.js +++ b/src/python/ripe_demo/static/js/ripe.js @@ -844,7 +844,8 @@ ripe.Ripe.prototype._cacheURL = function(url, options, callback) { // determines if the current request should be cached, obeys // some of the basic rules for that behaviour - var cached = !options.force && ["GET"].indexOf(options.method || "GET") !== -1; + var cached = typeof options.cached === "undefined" ? true : options.cached; + cached = cached && !options.force && ["GET"].indexOf(options.method || "GET") !== -1; // initializes the cache object in the current instance // in case it does not exists already