我想用 etags 和角度拦截器创建一个缓存解决方案。一切正常,但我无法返回缓存的数据。我想304 Not Modified
用缓存的数据覆盖响应。
'responseError': function(rejection) {
if(rejection.status === 304){
var response = {};
var url = rejection.config.url;
var params = rejection.config.params || {};
var etagKey = url+'.'+JSON.stringify(params);
var storedValue = $localStorage['ETag-Cache'+etagKey] || '{}';
var cachedObj = JSON.parse(storedValue);
console.log('CACHED ETag-Cache'+etagKey,cachedObj.response);
//I'd like to return with the cached data here but this doesn't work
return cachedObj.response;
}
return $q.reject(rejection);
}
下面的示例请求
$http.get('/api/bigdata', {
}).then(function(resp){
//I'd like to get the cached data in the resp variable
});