title: angularJS/ionic cannot read property 'then' of undefined
body: <p>I'm adding Caching to my App everything works fine from caching data, getting it expired and re-cache. When I implemented the functionality of putting the same expired data in the cache again if there is no connection I get this error: <code>Cannot read property 'then' of undefined</code> </p>
  
  <p>Here is the code of my controller:</p>
  
  <pre><code>.controller('ItemsCtrl', function($scope, $http, DSCacheFactory) {
  
      //handle the catche to hold the items lits.
      self.itemsCache = DSCacheFactory.get("itemsCache");
      /*
      *Function to re-refresh the cach after expire
      *re-use the old cache if no internet connection available
      */
      self.itemsCache.setOptions({
          onExpire: function(key, value){
              getItems()
                  .then(function(){
                  console.log("Items Cache was automatically refreshed", new Date());
              }, function(){
                  console.log("Errorgetting data put expired item back in the cache", new Date());
              });
          }
      });
  
      function getItems(){
          var cacheKey = "items",
              itemsData = self.itemsCache.get(cacheKey);
          if(itemsData){
              // if data in the cache dont make  HTTP calls.
              console.log("Found Data in cache", itemsData);
              //recive Data from the cache
              $scope.items = itemsData;
          }
          else{//if no data in the catch make HTTP calls.
              //HTTP request to get the items data.
              $http.get('services/data.json')
               .success(function(data){
                  console.log("Recived data via HTTP");
                  //caching the data recived from the http calls.
                  self.itemsCache.put(cacheKey, data);
                  $scope.items = data;
              });
          }//end of the else statment
      }
      getItems();
  })
  </code></pre>