i have a poltergeist with this code:
javascript code:
var cache = {};
cache.init = function()
{
if(typeof(this.memory)=='undefined')
this.memory = {};
};
cache.set = function(key, value)
{
this.memory[key] = value;
};
cache.get = function(key)
{
if(console)
{
console.log("memory: ");
console.log(cache.memory);
console.log("key: "+key);
console.log(cache.memory[key]);
}
if(typeof(cache.memory[key])!='undefined')
return cache.memory[key];
return false;
};
var route = {};
route.load = function(url)
{
var route_list = cache.get('route_list');
if(route_list==false)
{
route_list = this.getList();
cache.set('route_list', route_list);
}
return route_list;
};
route.getList = function()
{
var result = false;
$.ajax(
{
url: 'route.json',
dataType: 'json',
async: false,
success: function(json)
{
result = json;
}
});
return result;
};
cache.init();
route.load();
route.load();
i would like to cache some objects in client side with "cache" set and get.
content of route.json file:
{
"/example":
{
"controller": "example"
},
"/example/show":
{
"controller": "example",
"method": "show"
}
}
and the result in firebug is:
memory:
Object
{
route_list
Object { /example={...}, /example/show={...}}
}
key: route_list
undefined
why is undefined? i can navigate inside the object with firebug o.O
EDIT: i added the second call of route.load(); that i get undefined key