Am creating a web page that used ajax to load content and localCache
technique to store loaded page for later use. Everything seems to work well except that i will like to ignore some page which i have also implemented a simple method to do that but the problem is when the URL is full https://example.com/view_item.php
it won't ignore it but view_item.php
it will ignore. and also some page that has url parameter it won't ignore it too view_item.php?item=123
, view_item.php?item=123&title=abc
or https://example.com/view_item.php?item=123 etc
because i can't add those url in ignore array as it do change. I suggest that this can be archived using regex
but am not show how.
var localCache = {
data: {},
remove: function (url) {
delete localCache.data[url];
},
exist: function (url) {
return localCache.data.hasOwnProperty(url) && localCache.data[url] !== null;
},
get: function (url) {
console.debug('fatching data from URL ', url);
return localCache.data[url];
},
set: function (url, check, cachedData, callback) {
if(this.ignore(check)){
console.debug('Need To Ignore URL ', check);
}else{
localCache.remove(url);
localCache.data[url] = cachedData;
console.debug('caching data from URL ', url);
if ($.isFunction(callback)) callback(cachedData);
}
},
ignore: function(url){
var Arrays = [
'cart.php',
'favorites.php',
'view_item.php'
];
return ($.inArray( url, Arrays ) !== -1);
}
};