Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8576707
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T19:59:09+00:00 2026-06-11T19:59:09+00:00

i have a poltergeist with this code: javascript code: var cache = {}; cache.init

  • 0

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

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T19:59:10+00:00Added an answer on June 11, 2026 at 7:59 pm

    OK, now I can see your issue. Your code

    route.load();
    route.load();
    
    1. tries to get the [uncached] value from the cache:
      1. this logs the memory object
      2. and logs undefined because there is nothing
    2. because it returned false
      1. get the JSON synchronously
      2. and set it in the cache
    3. again tries to get the [cached] value
      1. logs the memory object
      2. and logs the cached object

    Everything is executed correctly. Now, you see the memory object two times in your console – but it is the same object, in its current state when inspecting it and not in the state when you logged it. See also

    • How can I change the default behavior of console.log? (*Error console in safari, no add-on*)
    • Bug in console.log?
    • Wrong value in console.log
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

have a php code like this,going to convert it in to C#. function isValid($n){
Have a look at this code sample or go to the jsfiddle function printRelation(a,
Have following listener for keyboard ArrowDown event(it's key code is 40 ): window.onload =
have anyone can tell me what syntax error on this actionscript (actionscript3.0)? var rotY:
Have some code: using (var ctx = new testDataContext()) { var options = new
Have a look at this code: I am trying to read in a number
Have the following code: String s= v.request(engine/?key=, P4z72NmBa91&method=load); JSONParser parser = new JSONParser(); Object
Have a look at this piece of C++ code: class Foo { int a;
have written this little class, which generates a UUID every time an object of
have a problem. At first look at this HTML <div id=map style=background-image: url(map.png); width:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.