2016-08-02 11 views
0

こんにちは、私はキャッシュポリシーについて読んだことがあります。私の目的は、リクエストキャッシュを3分に設定することです。レスポンスキャッシュは3分です。古いキャッシュを1日間保管してください。私たちが使うべき実装は何ですか?デフォルトのベローズのほかに変更できる設定はありますか? (私は要求と応答のためにAFNetworking 3を使用します)。どんな助けでも大変感謝しています。おかげどのキャッシュメソッドをIOSアプリケーションで使用する必要がありますか

NSURLRequestCachePolicy 

NSURLRequest has a cachePolicy property, which specifies the caching behavior of the request according to the following constants: 

NSURLRequestUseProtocolCachePolicy: Caching logic defined in the protocol implementation is used for a particular URL load request. This is the default policy. 
NSURLRequestReloadIgnoringLocalCacheData: Data should be loaded from the originating source. No existing cache data should be used. 
NSURLRequestReloadIgnoringLocalAndRemoteCacheData: Not only should the local cache data be ignored, but proxies and other intermediates should be instructed to disregard their caches so far as the protocol allows. 
NSURLRequestReturnCacheDataElseLoad: Existing cached data should be used, regardless of its age or expiration date. If there is no existing data in the cache corresponding to the request, the data is loaded from the originating source. 
NSURLRequestReturnCacheDataDontLoad: Existing cache data should be used, regardless of its age or expiration date. If there is no existing data in the cache corresponding to the request, no attempt is made to load the data from the originating source, and the load is considered to have failed, (i.e. “offline” mode). 
NSURLRequestReloadRevalidatingCacheData: Existing cache data may be used provided the origin source confirms its validity, otherwise the URL is loaded from the origin source. 

答えて

1

あなたには、いくつかの理由で完全にキャッシュ殺すためにしようとしている場合を除きあなたはほとんど常にNSURLRequestUseProtocolCachePolicyを使用する必要があります。

キャッシュの持続時間は、サーバーの応答の一部として(Cache-Controlヘッダー内に)設定する必要があります。 iOS URLキャッシュは、そのヘッダーで指定されたポリシーに従います。

+0

ご協力いただきありがとうございます。 NSURLRequestUseProtocolCachePolicyプロパティを変更するためのカスタマイズの例はありますか? –

+0

キャッシュへの途中でCache-Controlヘッダーを変更しようとしていますか?その例があるかどうかわかりませんが、おそらく 'URLSession:dataTask:willCacheResponse:completionHandler:'デリゲートメソッドを実装し、変更された**メソッドに基づいて新しい** NSCachedURLResponse **オブジェクトを作成することでそれを実行しますNSURLResponse **異なるヘッダー値を含むオブジェクト。 – dgatwood

+0

はいサーバーがヘッダーにキャッシュされたものをサポートしていない場合(キャッシュ時間、サイズ、有効期間を設定するために)、キャッシュの独自の実装を使用するようにカスタマイズすることを意味します。 –

関連する問題