Browser-based caching mechanism

Source: Internet
Author: User
Tags http authentication

Types of 1.web caches:

(1) Caching of databases

We may have heard of memcached (high-performance cache system), which is a database-level caching scheme, database caching is that when the relationship between Web applications is more complex, the database of many tables, if the frequent database query, it is easy to cause the database overwhelmed. In order to provide the performance of the query, the data of the query can be stored in the cache, the next time the query, directly from memory directly back. High efficiency.

(2) CDN Cache

CDN caches are typically deployed by webmasters themselves, in order to make their sites easier to scale for better performance, typically Web requests to the Cdn Gateway, which correspond to one or more load-balanced servers behind the gateway server, are based on their load requests, Dynamically forwards the request to the appropriate source server. From a browser perspective, the entire CDN is a source server, and from that level, the caching mechanism between the browser and the server is used in this structure.

(3) Proxy Server cache is the intermediate server between the browser and the server, the browser initiates a request to the intermediary server, and then sends the request to the source server after processing. Proxy server caching works like a browser, but it's bigger.

(4) The browser implements HTTP caching, and when we interact with the server using the HTTP protocol through the browser, the browser is cached based on a set of rules that are agreed with the server.

(5) Application-level caching refers to our cache at a large level, through the code logic to cache the data or resources we have requested, and then we need the data in a logical process to select the available cache data.

2. Why do I need a browser cache? What do we need to do?

We know the HTTP protocol, which consumes time when the client and browser resumes are connected, and a large response requires multiple communication between the client and the server to get a full response. This delays the time that the browser can consume and process content, which increases the cost of accessing the server's data and resources, so it is important to consider when reusing previous data using the browser's caching mechanism to program performance optimizations

Workaround: Develop a clear caching strategy for each resource, define whether the resource can be cached, who caches it, how long it can be cached, and how effectively to re-verify when the cache expires, and when the server returns a response, it needs to respond to the Cache-control and ETag provided in the header.

3. Verifying the cached HTTP response using the ETag

Server through the ETag HTTP header to pass the verification code, when the browser resource expires again after the request is, the sun relatives by default through the If-none-match pass the ETag verification code, through the verification code can be memory efficient resource update detection, if the resource has not changed, will not transfer any data.

The ETag is primarily the validation of whether the resource has been modified after the response expires.

If the browser issued a consistent code, indicating that the resource has not been modified, the server will return the lock, so that we can skip the download, take advantage of the resources already cached.

4. What is Cache-control? How do I define a cache-control policy?

The Cache-control response header in the response header when the server responds to a browser request enables each resource to define its own cache policy through the Cache-control HTTP header.

No-cache: Indicates that the response returned must be confirmed with the server before it can be used to satisfy subsequent requests to the same URL. Therefore, if there is an appropriate authentication token (ETAG), No-cache initiates a round-trip communication to validate the cached response and avoids the download if the resource has not been changed.
No-store: Disables caching of any responses, meaning that each time a user requests a resource, a request is sent to the server, and the full response is downloaded each time.
Public: If the response is marked as public, the response can be cached even if there is an associated HTTP authentication and even the response status code is not cached properly.
Private: The browser can cache the private response, but it is usually cached only for a single user, so no proxy server is allowed to cache it. For example, the user browser can cache HTML pages that contain user private information, but the CDN cannot cache.
Max-age: The maximum amount of time (in seconds) used to set the resource to be cached.

5. How are cached responses updated and deprecated?

In general, all HTTP requests made by the browser are routed first to the browser's cache to see if a valid response is cached that can be used to implement the request, and if there is a matching response, the response is read directly from the cache, thus avoiding network latency and the data costs of the transmission, however, What if we want to follow a new or obsolete cached response? Let's say we've already told a CSS style cache for up to 24 hours, but the designer just submitted the update, and we want all users to be able to use it, how can we notify all visitors that the cached CSS copy is obsolete.

A new user who has not previously requested the resource will get an updated resource, but the user who has requested the resource will always get the old cached resource until the expiration time is reached until he manually cleans up the browser's cache. Manually clean up your browser cache this can only be done by programmers, so what can we do to get the updated resources?

Browser-based caching mechanism

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.