title: How to put and read a complex object in cache?
body: <p>I have the following code which adds a javascript complex object (tree), you can see it as an array of arrays which values are objects themselves.</p>
  
  <p>I want to put in cache like this:</p>
  
  <pre><code>localStorage.Terms = tree;
  </code></pre>
  
  <p>but when reading it, in the console, it appears as <code>object object</code></p>
  
  <pre><code>function GetTermsDataFromTaxonomy(){
      var start = new Date().getTime();
      //Current Context
      var context = SP.ClientContext.get_current();           
      //Current Taxonomy Session
      var taxSession = SP.Taxonomy.TaxonomySession.getTaxonomySession(context);           
      //Term Stores
      var termStores = taxSession.get_termStores();           
      //Name of the Term Store from which to get the Terms.
      var termStore = termStores.getByName("Taxonomy_kl5tZjInn7STsFTzIE7n3Q==");          
      //GUID of Term Set from which to get the Terms.
      var termSet = termStore.getTermSet("31da4bc1-6429-499a-9d5e-be5e18b13c87");         
      var terms = termSet.getAllTerms();          
      context.load(terms);
  
      context.executeQueryAsync(function(){   
              var termEnumerator = terms.getEnumerator(), tree = {
                  term: terms,
                  children: []
              };
              var termList = "Terms: \n";                 
              while(termEnumerator.moveNext()){                       
                  var currentTerm = termEnumerator.get_current(); 
                  var currentTermPath = currentTerm.get_pathOfTerm().split(';');
                  var children = tree.children;
  
                   // Loop through each part of the path
                  for (var i = 0; i &lt; currentTermPath.length; i++) {
                      var foundNode = false;        
                      for (var j = 0; j &lt; children.length; j++) {
                          if (children[j].name === currentTermPath[i]) {
                              foundNode = true;
                              break;
                          }
                      }
  
                      // Select the node, otherwise create a new one
                      var term = foundNode ? children[j] : { name: currentTermPath[i], children: [] };
  
                      // If we're a child element, add the term properties
                      if (i === currentTermPath.length - 1) {
                          term.term = currentTerm;
                          term.title = currentTerm.get_name();
                          term.guid = currentTerm.get_id().toString();
                      }
  
                      // If the node did exist, let's look there next iteration
                      if (foundNode) {
                          children = term.children;
                      }
                      // If the segment of path does not exist, create it
                      else {
                          children.push(term);
  
                          // Reset the children pointer to add there next iteration
                          if (i !== currentTermPath.length - 1) {
                              children = term.children;
                          }
                      }
                  }               
              }
              localStorage.Terms = tree;
              var end = new Date().getTime();
              var time = end - start;
              console.log('Execution time: ' + time);             
          },
              function(sender,args){          
                console.log(args.get_message());              
          });
  }
  
  
  function GetAllTermsRecursive(){
      if(typeof(Storage) !== "undefined") 
      {
          var lastRefreshDateFromTermStore = localStorage.LastRefreshDateFromTermStore;
  
          //get data when the code is executed
          var currentDate = new Date();
          var day = currentDate.getDate();
          var month = currentDate.getMonth() + 1;
          var year = currentDate.getFullYear();
          var today = new Date(year, month, day, 0,0,0,0);
  
          if(lastRefreshDateFromTermStore &lt; today){
              localStorage.removeItem('Terms');
              localStorage.removeItem('LastRefreshDateFromTermStore');            
          }
  
          //Check if data has been cached.
          if(typeof(localStorage.Terms)  !== "undefined")
          {   
              var start = new Date().getTime();
              var terms=localStorage.Terms;
              var end = new Date().getTime();
              var time = end - start;
              console.log('Execution time with cache: ' + time);
          }
          else
          {
              //get date for when the data is cached
              var currentDate = new Date();
              var day = currentDate.getDate();
              var month = currentDate.getMonth() + 1;
              var year = currentDate.getFullYear();
              var cachedDate = new Date(year, month, day, 0,0,0,0);
  
              localStorage.LastRefreshDateFromTermStore = cachedDate;
              GetTermsDataFromTaxonomy();         
          }           
      }
      else {
              alert("Cache not sopported in old browsers, please upgrade");
      }   
  }
  </code></pre>