본문 바로가기
IT/web

[http] no-store, no-cache

by 내일은교양왕 2024. 5. 13.

Cache-Control: no-store

이 지시어는 캐시가 전혀 이루어지지 않도록 합니다. 즉, 서버의 응답은 어떤 형태로든 저장되거나 캐시되어서는 안 됩니다. 이는 매우 민감한 데이터를 다룰 때 사용됩니다. 

router.get('/no-store', (req, res) => {
  // Cache-Control: no-store 지시어로 설정하여 캐시 저장을 전면 금지
  res.setHeader('Cache-Control', 'no-store');
  res.send('This response cannot be stored in any cache.');
});

 

 

Cache-Control: no-cache

이 지시어는 응답이 저장되는 것은 허용하지만, 재사용하기 전에 서버에 검증을 요청해야 합니다. 서버는 요청의 If-None-Match (ETag) 또는 If-Modified-Since (Last-Modified) 헤더를 검사하여, 캐시된 사본이 여전히 유효한지 확인하고, 유효하다면 304 Not Modified 응답을 보냅니다.

router.get('/no-cache', (req, res) => {
  // Cache-Control: no-cache 지시어로 설정하여 캐시 검증을 요구
  res.setHeader('Cache-Control', 'no-cache');
  res.send('This response can be stored but must be validated before reuse.');
});

 

첫 호출 시 200 OK와 Etag를 넘겨준다.

HTTP/1.1 200 OK
X-Powered-By: Express
Cache-Control: no-cache
Content-Type: text/html; charset=utf-8
Content-Length: 63
ETag: W/"3f-KUhX7p5EIxh4lKwjIiyUFsWhICg"
Date: Mon, 13 May 2024 10:59:39 GMT
Connection: keep-alive
Keep-Alive: timeout=5

 

 

두번째 호출 시 캐쉬되는 것을 확인할 수 있다.

HTTP/1.1 304 Not Modified
X-Powered-By: Express
Cache-Control: no-cache
ETag: W/"3f-KUhX7p5EIxh4lKwjIiyUFsWhICg"
Date: Mon, 13 May 2024 11:00:05 GMT
Connection: keep-alive
Keep-Alive: timeout=5

'IT > web' 카테고리의 다른 글

[http] vary header로 dynamic cache 다루기  (0) 2024.05.14
[http] cache-control: max-age  (0) 2024.05.14
[http] If-Modified-Since, If-None-Match  (0) 2024.05.13
[http] turnnel  (0) 2024.05.10
[http] MIME  (0) 2024.05.10