"Deng Geqi case of mind 6" - HTTP caching mechanism

  We often say that the page has a cache ~! The cache has Css ~! If we open the console, but also often see a man named Cache-Control field, but the field, there are many kinds of value, there are many students do not understand what it means - these values are
  the values not only in practice will often use to, but also frequently mentions in the interview, so today we have to look at the meaning of these values with it -
"Deng Geqi case of mind 6" - HTTP caching mechanism
  in fact, cache-control in the field is divided into two categories, one is RequestHeader used, the other is ResponseHeader used, or that we are the most common and the most relevant is the front-end cache-control ResponseHeader used.
  Today we use the example of Deng brother to take medicine, to explain the various values of the Cache-Control ResponseHeader is for everyone -
  Deng brother's situation can use a word to describe it is "the wave of more than a dull boy." One day Deng brother suddenly found that his mind enough. And decided to buy some drugs, we can not let this situation deteriorate further down ~
  So Deng brother went to the pharmacy, pharmacy doctor met with Deng brother, suddenly overjoyed and said: "!!? Yeah Deng brother coming ~ ~ want to eat today Diansha" after Deng brother described his situation to the pharmacy to the doctor, the doctor recommended to the pharmacy shop signs Deng brother [brain] debris. Our story is this - the beginning
  then we can put Deng brother likened browser, pharmacies likened server, pharmacy physician than as proxy servers, brain debris is to request a resource, such as a picture like ~
  1 .max-age:
  Deng brother has a knack to buy back more than seven days you do not eat, you have to buy new ones. (Even if not overdue not eat - eat more if it expired the ~)
  This is the role of the max-age cache of resources, not more than a certain time, it is necessary to re-request. If you buy back time is No. 1, the expiration time the brain fragments is No. 5, although Deng brother to accept the drug in their homes put seven days, but because No. 5 expired, so Deng brother after No. 5 still have to re-buy of. behind the max-age it is usually followed by a sequence number that represents the number of seconds the cache.
  2.max-stale:
  sometimes Deng brother is very frugal, and some things will also expire a few days to eat.
  This is the role of max-stale, outdated little time does not matter, can also be used. later followed in seconds max-stale, outdated indicate how long things can continue to use.
  max-stale most of the time will be used along with the max-age. If the brain pieces No. 1 to buy, Deng brother up to seven days (to 7), but the brain pieces No. 5 expires, if the max-stale = 4, then it means that Deng brother acceptable brain damage in the expired four days sheet.
  That is the equivalent of brain fragments Deng brother think it can not eat after 9. But Deng brother can only tolerate drugs at home seven days, so the number of August Deng brother will go to buy medicine again (re-request the resource).
  3.no-cache
  Deng brother is also very cautious sometimes convulsions, and before each medication should go to the pharmacy, let the doctor look at the drug can not eat. In case there is a problem which approved the drug was recalled to it ~ (Ps: you know)
  this is the role of no-cache, no-cache does not directly use the cache, but each time before using the resources, we must ask the server Xianxiang about this resource can not be used, if they can use to continue to use, if you can not use it to re-request.
  4.no-store
  sometimes Deng brother is also very Tyrant of each medication should buy a new bottle. Every time a new eat. (The first time, Deng brother's cell phone, too, have no electricity each time to buy a new, and then I was able to charge mobile phones ...)
  This is a very no-store, very Tyrant practice, every time a request to the server resources. If all server resources this will cause a lot of pressure, so we are very sensitive to the kind of data to data limitations, would do such operations.
  5.public
  Deng brother home with a lot of brain fragments, since Deng brother often buy pieces of brain, so a doctor will enter the pharmacy joked: "? Again to buy pieces of brain matter"
  public representation cache can be cached anywhere, pharmacies server, proxy server is equivalent to a doctor, pharmacy doctor can know Deng brother to buy a brain fragments prove that the proxy server has cached Deng brother to buy things. So the public can refer to any local cache resources.
  6.private
  Some doctors are very serious, not every joke and Deng brother. So sometimes Deng brother go to the pharmacy, the doctor will be very polite and smiling Deng brother asked: "What can I do today ~?"
  Private means that only means that allows the client cache, the proxy server can not cache this resource.
  7.must-revalidation
  Sometimes, Deng brother is busy, Mrs. Deng Deng brother will give prepared with some medicine. When Deng Sao hands of drug expired, Mrs. Deng will go to the pharmacy to buy medicine.
  Brother and Sister Deng Deng is equivalent to the same browser in two windows. max-age, and must-revalidation after expiration are local to the server re-request resources. But the difference is that, if max-age, so if resources are not expired, the newly opened window will use this resource. If this is must-revalidation, each time a new window is opened, the request will go to the server resources.
  8.no-transform
  Deng brother's brain fragments is imported, the labels are in English, and sometimes a pharmacy doctors worry that patients do not know the word on the bottle, put the word translated written on the label, then posted up. However, if the manufacturer claims, the resource can not make any changes in the middle of the operation, the doctor will not give pharmacy bottle labeled a ~.
  Usually when transfer pictures or resources, sometimes a proxy server in order to have better performance, the picture will be compressed or resources, or format conversion. But if this field with a header in the response, it means it is not allowed to make any changes to the resource in the middle of transmission.
  In addition to the above effect of these parameters are often asked, the will often ask to browser-dependent response for these parameters, different parameters plus the different operations will produce different actions. We can specifically what action will occur through the following table saw.
"Deng Geqi case of mind 6" - HTTP caching mechanism
  Above story is purely fictional, thanks to the strong support of Deng brother, "Deng Geqi case of mind" series. Finally, Deng brother added: "Medicine can not stop ~!"

Guess you like

Origin blog.51cto.com/13409950/2458104