2017-07-19 19 views
0

リクエストでヘッダーのキャッシュに苦労しています。

私のリソースであるが以下のようになります。

method: 'GET', 
cache: false, 
headers: { 
    session: auth.mySession() 
} 

プロバイダも設定されています。

config(['$httpProvider', function($httpProvider) { 
if (!$httpProvider.defaults.headers.get) { 
    $httpProvider.defaults.headers.get = {}; 
} 
$httpProvider.defaults.headers.get['Cache-Control'] = 'no-cache'; 
$httpProvider.defaults.headers.get['Pragma'] = 'no-cache'; 
}]). 

実際には機能しません。 セッションが削除されている間にリクエストが送信され、セッションが設定されていない場合は となります。 Ctrl + F5を押す必要がありました。

答えて

0

最後に、結果をキャッシュすることではなく、ヘッダー自体をキャッシュすることであることに気付きました。

ヘッダーは、ページの初期化段階で1回だけ計算されます。 その事実の直後、私は常に有効なセッションを要求のヘッダーに挿入するインターセプターソリューションを提供しました。

config(['$httpProvider', function($httpProvider) { 
    $httpProvider.interceptors.push('injectingSessionInterceptor'); 
}]). 
service('injectingSessionInterceptor', ['auth', function (auth) { 
    var ser = this; 
    ser.request = function (config) { 
     var session = auth.mySession(); 
     config.headers.session = session; 
     return config; 
    }; 
}]); 
関連する問題