본문 바로가기
  • AI (Artificial Intelligence)
Skills/Web

Cache Control

by 로샤스 2019. 10. 18.

안다, Cache를 사용하면 빠르다. 근데 꺼림직해.. 왠지 Sync가 맞지 않았을까 해서. 그래서 TTL(max-age)가 존재하겠지?
근데.. 어디다 이 것을 저장할까? 니가 저장해 나는 규칙을 줄게??

나는 이러한 상상을 펼친다. 학생 때는 물어볼 수도 있고 사수가 있다면 조언도 구하는데 이젠 없다.
내가 정한다. 그래서 잘 못 정해서 잘 못 되면 흠.. 애매한 위치 애매한 나이.. 뭔가 더 클리어 하게 이해하기 위해 가방끈도 길게하고
이것저것 읽어서 지식도 늘렸는데 더 몰라 ㅋㅋ

https://www.imperva.com/learn/performance/cache-control/

What is the Cache-Control Header

Cache-control is an HTTP header used to specify browser caching policies in both client requests and server responses. Policies include how a resource is cached, where it’s cached and its maximum age before expiring (i.e., time to live).

The cache-control header is broken up into directives, the most common of which are detailed below:

An example of an HTTP Response Header from google.com

Cache-Control: Max-Age

The max-age request directive defines, in seconds, the amount of time it takes for a cached copy of a resource to expire. After expiring, a browser must refresh its version of the resource by sending another request to a server.

For example, cache-control: max-age=120 means that the returned resource is valid for 120 seconds, after which the browser has to request a newer version.

Cache-Control: No-Cache

The no-cache directive means that a browser may cache a response, but must first submit a validation request to an origin server.

Cache-Control: No-Store

The no-store directive means browsers aren’t allowed to cache a response and must pull it from the server each time it’s requested. This setting is usually used for sensitive data, such as personal banking details.

Cache-Control: Public

The public response directive indicates that a resource can be cached by any cache.

Cache-Control: Private

The private response directive indicates that a resource is user specific—it can still be cached, but only on a client device. For example, a web page response marked as private can be cached by a desktop browser, but not a content delivery network (CDN).

Additional HTTP Cache Headers

In addition to cache-control, notable HTTP cache headers include:

  • Expires – This header specifies a fixed date/time for the expiration of a cached resource. For example, Expires: Sat, 13 May 2017 07:00:00 GMT signals that the cached resource expires on May 13, 2017 at 7:00 am GMT. The expires header is ignored when a cache-control header containing a max-age directive is present.
  • ETag – A response header that identifies the version of served content according to a token – a string of characters in quotes, e.g., "675af34563dc-tr34" – that changes after a resource is modified. If a token is unchanged before a request is made, the browser continues to use its local version.
  • Vary – A header that determines the responses that must match a cached resource for it to be considered valid. For example, the header Vary: Accept-Language, User-Agent specifies that a cached version must exist for each combination of user agent and language.

CDNs and Cache-Control

The variety of caching headers can make manual cache management overwhelming. CDNs allow for granular cache policy management through a user-friendly dashboard, relieving you of the need to manually tweak individual headers.

In addition to simplifying cache management, CDNs augment the browser caching process using proxies. Proxy caching brings content closer to site visitors, accelerating the delivery of locally stored resources. This is especially beneficial for first-time visitors whose browsers have yet to cache site content.

Finally, more advanced CDNs use advanced automation techniques, including machine learning, to cache dynamically generated content and resources. This optimizes your caching policies and further speeds up content delivery.

 

 

 

Reference: https://www.imperva.com/learn/performance/cache-control/

 

'Skills > Web' 카테고리의 다른 글

Building "utility-first" design systems (1/3)  (0) 2020.12.22
Cache for web  (0) 2019.10.18
jQuery.get()  (0) 2016.01.05
jQuery를 이용한 Modal 생성  (0) 2015.12.31
How to install Tomcat on CentOS 7  (0) 2015.12.23

댓글