2014-01-15 71 views
0

我已添加緩存:對我的資源爲true。但是當我再次執行資源方法(不刷新頁面)時,我發現請求被髮送到服務器。爲什麼資源沒有被緩存?我應該實現$ cacheFactory這個工作嗎?緩存:true被資源忽略

資源:

"use strict"; 
angular.module('afx.service') 
    .factory('afx.service.resource.Terminal', ["$resource", function ($resource) { 
     return $resource("/rest/terminals", {}, { 
      /** 
      * @method findTerminals 
      * Find all terminals 
      * @return {Array} Terminals 
      */ 
      findTerminals: { method: "GET", isArray: true, cache: true} 

     }); 
    }]); 

利用資源:

terminalsResource.findTerminals({}, function (data) { 
        $scope.loading = false; 
        $scope.terminals = data; 
       }, function (response) { 
        var lStatus = response.status; 
        if (lStatus !== 401) { 
         growlerService.error("Could not refresh the terminals"); 
        } 
       }); 
+0

可以告訴你我們的代碼? – michael

回答

0

只能在角resource.js v1.2.7(不1.0.7)

1

您必須實現$ cacheFactory做到這一點!

在這裏看看:AngularJs: How to cache $http properly?

+0

執行此操作,還是讓資源(GET,同一個URL)對服務器做2次調用 – Vincent

+0

你在瀏覽器上做F5嗎?因爲在F5上,你總是會得到200像狀態代碼 –

+0

jep,我只更新angular.js到1.2.7 ... Angular-Resource.js是stil 1.0.7。它現在像一個魅力,沒有實現$ cacheFactory。 – Vincent