Nice programing

Cache-Control : max-age = 0과 no-cache의 차이점은 무엇입니까?

nicepro 2020. 10. 2. 23:17
반응형

Cache-Control : max-age = 0과 no-cache의 차이점은 무엇입니까?


헤더 Cache-Control: max-age=0는 콘텐츠가 즉시 부실한 것으로 간주되고 (다시 가져와야 함) 의미하며, 이는 사실상 Cache-Control: no-cache.


나는 동일한 질문을했고 내 검색에서 몇 가지 정보를 찾았습니다 (당신의 질문이 결과 중 하나로 나왔습니다). 내가 결정한 것은 ...

Cache-Control헤더 에는 양면이 있습니다 . 한쪽은 웹 서버 ( "원본 서버"라고도 함)에서 전송할 수있는 곳입니다. 다른 쪽은 브라우저 ( "사용자 에이전트"라고도 함)에서 전송할 수있는 곳입니다.


원본 서버에서 보낸 경우

저는 믿습니다 max-age=0단순히 응답에서 부실 캐시 (사용자 에이전트) 알려주는 GET-가서 그들은 있도록 해야한다 응답을 재 검증 (예.와 If-Not-Modified헤더) 캐시 된 복사본을 사용하기 전에, 반면 no-cache그들에게 말한다 해야 캐시 된을 사용하기 전에 재 검증 부. 14.9.1 부터 캐시 가능한 항목 :

캐시 없음

... 캐시는 원 서버와의 성공적인 재 검증없이 후속 요청을 만족시키기 위해 응답을 사용해서는 안됩니다. 이를 통해 원본 서버는 클라이언트 요청에 대한 부실 응답을 반환하도록 구성된 캐시에서도 캐싱을 방지 할 수 있습니다.

즉, 캐시는 때때로 부실 응답을 사용하도록 선택할 수 있지만 (그런 다음 Warning헤더 를 추가해야한다고 생각 하지만) no-cache무슨 일이 있어도 부실 응답을 사용할 수 없다고 말합니다. 아마 당신은 싶어 SHOULD 야구 통계가 페이지에서 발생하는 경우 -revalidate 동작을, 그러나 당신은 싶어 MUST 당신이 전자 상거래 구매에 대한 응답을 생성 한 경우 -revalidate 동작을.

no-cache저장을 막을 수 없다고 말했을 때 귀하의 의견이 정확하지만 실제로 사용할 때 또 다른 차이점이 될 수 있습니다 no-cache. 나는 Cache Control Directives Demystified 페이지를 보았습니다 . (정확성을 보증 할 수 없습니다) :

실제로 IE와 Firefox는 브라우저가 페이지를 캐시하지 않도록 지시하는 것처럼 no-cache 지시문을 처리하기 시작했습니다. 우리는 약 1 년 전에이 행동을 관찰하기 시작했습니다. 이 변경은 캐싱을 방지하기 위해이 지시문을 광범위하게 (그리고 부정확하게) 사용했기 때문에 촉발 된 것으로 보입니다.

...

최근에는 "cache-control : no-cache"도 "no-store"지시어처럼 작동하기 시작했습니다.

제쳐두고, 그것은 Cache-Control: max-age=0, must-revalidate기본적으로 Cache-Control: no-cache. 그래서 아마도 그것 과 같은 일을하는 것으로의 명백한 마이그레이션을 피하면서 (즉, 캐싱이 아님) must -revalidate 동작 을 얻는 방법 일까요?no-cacheno-cacheno-store


사용자 에이전트가 보낸 경우

shahkalpesh의 답변 이 사용자 에이전트 측에 적용 된다고 생각 합니다. 13.2.6 Disambiguating Multiple Responses를 볼 수도 있습니다 .

사용자 에이전트가 요청을 보내면 Cache-Control: max-age=0(일명 "종단 ​​간 재 검증"), 각 캐시 If-Not-Modified는 원본 서버까지 캐시 항목 (예 : 헤더 포함) 을 재 검증 합니다. 응답이 304 (수정되지 않음)이면 캐시 된 엔티티를 사용할 수 있습니다.

반면에 Cache-Control: no-cache(일명 "end-to-end reload") 요청을 보내는 것은 재 검증되지 않으며 서버 는 응답 할 때 캐시 된 사본을 사용 하지 않아야 합니다.


최대 연령 = 0

이것은 새로 고침 을 클릭하는 것과 동일합니다. 즉, 이미 최신 사본이없는 경우 최신 사본을 제공합니다.

캐시 없음

이 들고 Shift 키를 수단, 그냥 상관없이 모든 것을 다시하지 새로 고침을 클릭하는 동안.


지금은 오래된 질문이지만 다른 사람이 내가 한 것처럼 검색을 통해이를 발견하면 IE9에서 뒤로 및 앞으로 버튼을 사용할 때 리소스의 동작을 구성하는 데 이것을 사용하는 것으로 보입니다. 최대 사용 기간 = 0 사용되는 뒤로 / 앞으로 눌러에 자원을 볼 때, 브라우저는 최신 버전을 사용합니다. 캐시 가 사용 되지 않으면 리소스가 다시 가져옵니다.

IE9 캐싱에 대한 자세한 내용은이 msdn 캐싱 블로그 게시물 에서 볼 수 있습니다 .


IE8 및 Firefox 3.5를 사용한 최근 테스트에서 둘 다 RFC를 준수하는 것으로 보입니다. 그러나 원본 서버에 대한 "친 화성"이 다릅니다. IE8은 no-cache응답을 max-age=0,must-revalidate. 파이어 폭스 3.5은, 그러나, 치료하는 것 no-cache과 동일하게 no-store성능과 대역폭 사용에 대한 짜증한다.

기본적으로 Squid Cache no-cache는 Firefox처럼 헤더 와 함께 아무것도 저장하지 않는 것 같습니다 .

내 조언은 public,max-age=0모든 요청에 ​​대해 최신 상태를 확인하려는 민감하지 않은 리소스 를 설정 하지만 캐싱의 성능 및 대역폭 이점을 허용하는 것입니다. 고려 사항이 동일한 사용자 별 항목의 경우 private,max-age=0.

나는의 사용을 피할 것 no-cache그것의 기능을 상당 일부 브라우저 인기 캐시에 의해 놨 된 것으로, 전체를 no-store.

또한 Akamai 및 Limelight를 에뮬레이션하지 마십시오. 기본적으로 대규모 캐싱 어레이를 주요 비즈니스로 실행하고 전문가 여야하지만 실제로는 네트워크에서 더 많은 데이터를 다운로드하는 데 관심이 있습니다. Google은 에뮬레이션을위한 좋은 선택이 아닐 수도 있습니다. 그들은 자원에 따라 max-age=0또는 no-cache무작위로 사용하는 것처럼 보입니다 .


최대 연령
    max-age = 0 지시문을 사용하여 중간 캐시가 강제로 재 검증되는 경우 
자체 캐시 항목이고 클라이언트는 요청에 자체 유효성 검사기를 제공했습니다. 
제공된 유효성 검사기는 현재 캐시 항목과 함께 저장된 유효성 검사기와 다를 수 있습니다. 
In this case, the cache MAY use either validator in making its own request without 
affecting semantic transparency. 

    However, the choice of validator might affect performance. The best approach is for the 
intermediate cache to use its own validator when making its request. If the server replies 
with 304 (Not Modified), then the cache can return its now validated copy to the client 
with a 200 (OK) response. If the server replies with a new entity and cache validator, 
however, the intermediate cache can compare the returned validator with the one provided in 
the client's request, using the strong comparison function. If the client's validator is 
equal to the origin server's, then the intermediate cache simply returns 304 (Not 
Modified). Otherwise, it returns the new entity with a 200 (OK) response. 

    If a request includes the no-cache directive, it SHOULD NOT include min-fresh, 
max-stale, or max-age. 

courtesy: http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.9.4

Don't accept this as answer - I will have to read it to understand the true usage of it :)


I'm hardly a caching expert, but Mark Nottingham is. Here are his caching docs. He also has excellent links in the References section.

Based on my reading of those docs, it looks like max-age=0 could allow the cache to send a cached response to requests that came in at the "same time" where "same time" means close enough together they look simultaneous to the cache, but no-cache would not.


By the way, it's worth noting that some mobile devices, particularly Apple products like iPhone/iPad completely ignore headers like no-cache, no-store, Expires: 0, or whatever else you may try to force them to not re-use expired form pages.

This has caused us no end of headaches as we try to get the issue of a user's iPad say, being left asleep on a page they have reached through a form process, say step 2 of 3, and then the device totally ignores the store/cache directives, and as far as I can tell, simply takes what is a virtual snapshot of the page from its last state, that is, ignoring what it was told explicitly, and, not only that, taking a page that should not be stored, and storing it without actually checking it again, which leads to all kinds of strange Session issues, among other things.

I'm just adding this in case someone comes along and can't figure out why they are getting session errors with particularly iphones and ipads, which seem by far to be the worst offenders in this area.

I've done fairly extensive debugger testing with this issue, and this is my conclusion, the devices ignore these directives completely.

Even in regular use, I've found that some mobiles also totally fail to check for new versions via say, Expires: 0 then checking last modified dates to determine if it should get a new one.

It simply doesn't happen, so what I was forced to do was add query strings to the css/js files I needed to force updates on, which tricks the stupid mobile devices into thinking it's a file it does not have, like: my.css?v=1, then v=2 for a css/js update. This largely works.

User browsers also, by the way, if left to their defaults, as of 2016, as I continuously discover (we do a LOT of changes and updates to our site) also fail to check for last modified dates on such files, but the query string method fixes that issue. This is something I've noticed with clients and office people who tend to use basic normal user defaults on their browsers, and have no awareness of caching issues with css/js etc, almost invariably fail to get the new css/js on change, which means the defaults for their browsers, mostly MSIE / Firefox, are not doing what they are told to do, they ignore changes and ignore last modified dates and do not validate, even with Expires: 0 set explicitly.

This was a good thread with a lot of good technical information, but it's also important to note how bad the support for this stuff is in particularly mobile devices. Every few months I have to add more layers of protection against their failure to follow the header commands they receive, or to properly interpet those commands.


I'm writing a series of articles that covers these topics in depth, that IMHO clearly not discussed enough among developers.

Browsers, private proxies and CDNs:
https://medium.com/free-code-camp/http-caching-in-depth-part-1-a853c6af99db

Cache-Control & Vary https://medium.com/@lojacquemin/an-in-depth-introduction-to-http-caching-cache-control-vary-e3229815ddf4


The difference is that no-cache (no-store on Firefox) prevents any kind of caching. That can be useful to prevent pages with secure content being written to disk and for pages that should always be updated even if they are re-visited with the back button.

max-age=0 indicates that a cache entry is stale and requires re-validation, but does not prevent caching. Often browsers only validate resources once per browser session, so the content may not get updated until the site is visited in a new session.

Usually, browsers will not delete expired cache entries, unless they are reclaiming the space for newer content when the browser cache is full. Using no-store, no-cache allows a cache entry to be explicitly deleted.

참고URL : https://stackoverflow.com/questions/1046966/whats-the-difference-between-cache-control-max-age-0-and-no-cache

반응형