URL 액세스를 통한 네트워크 요청 작성

3651 단어
먼저 코드 보기:
NSURLRequest *request = [NSURLRequest requestWithURL:url cachePolicy:(NSURLRequestCAchePolicy) timeoutInterval:(NSTiemInterval)  ]

여기 첫 번째 파라미터는 할 말이 없어요. 구체적으로 두 번째 파라미터는 NSURL Request CAche Policy입니다.
  NSURLRequestUseProtocolCachePolicy = 0,
   NSURLRequestReloadIgnoringLocalCacheData = 1,
   NSURLRequestReloadIgnoringLocalAndRemoteCacheData = 4, // Unimplemented
   NSURLRequestReloadIgnoringCacheData =    NSURLRequestReloadIgnoringLocalCacheData,
    NSURLRequestReturnCacheDataElseLoad = 2,
    NSURLRequestReturnCacheDataDontLoad = 3,
    NSURLRequestReloadRevalidatingCacheData = 5, 

저희가 다섯 가지 매거 유형을 볼 수 있는데 다음 설명을 해드릴게요. 먼저 xcode의 영어 해석을 볼게요.
@discussion The NSURLRequestCachePolicy enum defines constants that
    can be used to specify the type of interactions that take place with
    the caching system when the URL loading system processes a request.
    Specifically, these constants cover interactions that have to do
    with whether already-existing cache data is returned to satisfy a
    URL load request.

중국어 번역:
    @constant NSURLRequestUseProtocolCachePolicy Specifies that the
    caching logic defined in the protocol implementation, if any, is
    used for a particular URL load request. This is the default policy
    for URL load requests.

기초 전략
 @constant NSURLRequestReloadIgnoringLocalCacheData Specifies that the
    data for the URL load should be loaded from the origin source. No
    existing local cache data, regardless of its freshness or validity,
    should be used to satisfy a URL load request.

로컬 캐시 무시
    @constant NSURLRequestReloadIgnoringLocalAndRemoteCacheData Specifies that
    not only should the local cache data be ignored, but that proxies and
    other intermediates should be instructed to disregard their caches
    so far as the protocol allows.  Unimplemented.

모든 캐시 정책을 무시하고 로컬이든 원격이든 항상 원래 주소에서 다시 다운로드합니다
  @constant NSURLRequestReloadIgnoringCacheData Older name for
    NSURLRequestReloadIgnoringLocalCacheData.

NSURL Request Reload Ignoring CacheData는 NSURL Request Reload Ignoring Local CacheData의 옛 이름입니다. 이 두 가지는 같습니다.
    @constant NSURLRequestReturnCacheDataElseLoad Specifies that the
    existing cache data should be used to satisfy a URL load request,
    regardless of its age or expiration date. However, if there is no
    existing data in the cache corresponding to a URL load request,
    the URL is loaded from the origin source.

먼저 캐시를 사용하고 로컬 캐시가 없으면 원래 주소에서 다운로드합니다
  @constant NSURLRequestReturnCacheDataDontLoad  Specifies that the
    existing cache data should be used to satisfy a URL load request,
    regardless of its age or expiration date. However, if there is no
    existing data in the cache corresponding to a URL load request, no
    attempt is made to load the URL from the origin source, and the
    load is considered to have failed. This constant specifies a
    behavior that is similar to an "offline" mode.

로컬 캐시를 사용하고 다운로드하지 않습니다. 로컬에 캐시가 없으면 요청이 실패합니다. 이 정책은 주로 오프라인 작업에 사용됩니다.
    @constant NSURLRequestReloadRevalidatingCacheData Specifies that
    the existing cache data may be used provided the origin source
    confirms its validity, otherwise the URL is loaded from the
    origin source.  Unimplemented.

로컬 캐시가 유효하면 다운로드하지 않으며 다른 모든 경우 원래 주소에서 다시 다운로드합니다.
세 번째 파라미터는 지연 시간을 설정하는 것이다. 즉, 네가 그의 응답을 기다리는 시간이다.

좋은 웹페이지 즐겨찾기