我正在尝试向资源添加缓存,但在每次调用时,都会发出一个新的 ajax 请求。这里:
app.factory('States', function($resource,$locale,$cacheFactory) {
var cache = $cacheFactory('statesCache');
var StatesService = $resource( "api/ref/states-:country", {}, {
query: {
cache: cache, //With true it doesn't work either
method: 'GET',
isArray: true
}
});
return {
getList: function( country ) {
console.log( cache.info() );
return StatesService.query({
country: (country || "CA").toLowerCase()
});
}
}
});
然后每次调用都会States.getList( "CA" );
触发一个新的 Http 请求。控制台每次显示自定义缓存大小仍为 0:Object {id: "statesCache", size: 0}
角版是 v1.2.0-rc.3为 1.0.8