当前位置:网站首页>Simple collation of Web cache

Simple collation of Web cache

2022-06-25 00:16:00 You're like an ironclad treasure

1. What is? web cache ?

I understand it : Because the processor is very fast , To avoid spending a lot of time waiting for the network to request resources , Therefore, some frequently used resources will be stored locally , This is web cache .

2. web The role of caching ?

  • obvious , Speed up the page opening .
  • Reduce bandwidth , Because most of the resources are local , No network requests for resources .
  • Reduce server pressure , Reduce frequent server access .

3. web What are the caches ?

  • Database cache

Avoid frequent database queries , Put the queried data into memory , Return directly from memory next time .

  • Server cache

The server caches resources that are often used , When multiple users access , Because the resources they need to access together have been cached , It can effectively reduce the pressure on the server .

  • Browser cache

Cache some recently used pictures , data , Page etc. , Improve web page opening speed .

4. http Caching mechanism in

4.1 http1.0 in

  • Pragma Determine whether to use cache
  • Expires Represents the expiration date of the cache

From these two, we can know , Whether to use cache , And the expiration time of the cache .

4.2 http1.1 in

  • Cache-Control Instead of Pragma, It has several parameters ,

    • no-store: Disable all caches
    • no-chche: Whether the cache is expired or not , No caching .
    • max-age: Effective time of cache

From above we will find , We cached resources , But the browser doesn't know whether the resource has been updated , Whether new resources need to be loaded . So there is something below .

4.3 Last-Modified/If-Modified-Since

  • Last-Modified: Indicates the last modification time of the resource
  • If-Modified-Since: When resources expire , The browser will bring this key,value Namely Last-Modified.
  • The server will judge after receiving , Has the resource been updated .
    • If updated , Returns the new resource ,200, And the new last modification time
    • If there is no update , return 304

4.4 Etag/If-None-Match

Another way to judge whether a resource has been updated

  • Etag: The server gives each resource a unique identifier
  • If-None-Match: alike , Browser with Etag identification , The server judges , Decided to return 200, still 304.

4.5 The advantages and disadvantages of both

  • Etag Server operation is required , So the server performance will be destroyed .
  • Last-Modified In seconds , But sometimes resources will be in a second , Frequent changes , In this way, the cache function is lost .

5. cookie

  • We all use cookie, Store some data in it , Then send it as a header .

advantage :

  • Key value pair storage , Easy to use
  • The expiration time can be configured

shortcoming :

  • There's a limit to the size , Usually only 4k.
  • There are security issues ,cokkie Can be tampered with .

6 web stroage

webStorage Li Fen is sessionStorage and localStorage

  • sessionStorage: Just look at the name , Every session There is an independent storage space in each session , When the conversation is over, there is no .
  • localStorage: Local storage space , Even if the browser is closed , On opening , The data is still there .

7. indexdDB

Local database provided by browser , Can store more data , You can also create indexes .

  • indexedDB There are some advantages :
  • asynchronous
  • Key value pair storage
  • Business , You can roll back .
  • The space is big

summary

It is a simple understanding web Some knowledge of caching , There are a lot of articles in this field , If you are interested, you can find a lot on the Internet , Take a hole first , Next time I have time to practice ,12 Slightly , Happy New Year to you all .

原网站

版权声明
本文为[You're like an ironclad treasure]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202210551199585.html