Presentation is loading. Please wait.

Presentation is loading. Please wait.

Web Caching? Web Caching:.

Similar presentations


Presentation on theme: "Web Caching? Web Caching:."— Presentation transcript:

1 Web Caching? Web Caching:

2 Web Caching? Fetching something over the network is both slow and expensive. Large responses require many roundtrips between the client and server, This requires extra processing from the browser and incurs extra costs for the visitor (bandwidth) and the visited server. The ability to cache and reuse previously fetched resources is a critical aspect of performance optimization Almost, every browser coms with an implementation of an HTTP cache. When you visit a web page, the browser stores the web page in cache to make it load faster in subsequent visits. All you need is to ensure that each server response: Provides the correct HTTP header directives Use these headers to instruct the browser on: when and for how long the browser can cache the response Web Caching:

3 Web Caching? Storing copies of recently accessed web pages
Pages are delivered from the cache when requested again Browser caches Proxy caches Why Cache? Shorter response time Reduced bandwidth requirement Reduced load on servers Access control and logging Web Caching:

4 Browser Caching vs. Proxy Caching
Local hard drive space stores representation of viewed content. Usefulness Recently viewed pages (Back/Forward button) Commonly used images Proxy Caching Similar concept, but for multiple users. Usually implemented on a firewall or separate device known as intermediaries (Proxies). Usefulness Latency and network traffic are reduced Web Caching:

5 Cache Controlling HTML Meta Tags HTTP Headers HTTP Defining Mechanisms
Written in <head> section of an HTML page. Can mark expiration date or as un-cacheable. Only used by some browser caches and not seen by proxy caches. i.e. To disable browser cache, you can use: HTTP Headers Automatically created by Web server Sent before HTML Seen by browser and proxy caches HTTP Defining Mechanisms Freshness – Content is able to be loaded from cache without having to check with the original server Validation – The process of confirming with the original server whether or not cached content is still valid to load <meta http-equiv="Cache-Control" content="no-store" /> Web Caching:

6 HTTP Response Headers Example
Sample Response Header HTTP/ OK Date: Fri, 20 Oct :19:41 GMT Server: Microsoft IIS/8.5 Cache-Control: max-age=3600, must-revalidate Expires: Fri, 20 Oct :19:41 GMT Last-Modified: Mon, 16 Oct :28:12 GMT ETag: "3e fbbc" Content-Length: 1024 Content-Type: text/html Validation Freshness Web Caching:

7 Expires Header and Freshness
Expires: Fri, 20 Oct :19:41 GMT Indicates how long the representation is fresh. After this time passes, the cache will communicate with the original server to see if there have been any changes. Beneficial for static page images as well as continually changing content. Web server and cache must be synchronized. Web Caching:

8 Last-Modified and Validation
Last-Modified: Mon, 16 Oct :28:12 GMT Validate cache by looking at the last time the document was altered (Last-Modified). If-Modified-Since request is sent to the original server. If changes have been made since the date given, the entire document is returned. Otherwise, the cached document can be loaded. Web Caching:

9 ETag and Validation Unique identifiers created by server.
ETag: "3e fbbc" Unique identifiers created by server. Changed each time the representation is altered on the original server. If-None-Match request is sent to server and a simple comparison is used to validate the content. Web Caching:

10 Browser Caching Ex. This example shows that the server returns:
First Request This example shows that the server returns: a 1024-byte response, instructs the client to cache it for up to 120 seconds, and provides a validation token ("x234dff") that can be used after the response has expired to check if the resource has been modified. ETag validation token enables efficient resource update checks No data is transferred if the resource has not changed. It is used as a fingerprint of the file contents On the second request, the client only needs to send it to the server The server checks the token against the current resource If the token hasn't changed, the server returns a "304 Not Modified" response This means, cache hasn't changed and it can be renewed for another 120 seconds. Note: no need to download the response again, which saves time and bandwidth. When the server returns a response, it includes a set of HTTP headers. i.e. content-type, length, caching directives, validation token, etc. Second Request

11 Cache-Control Each resource can define its caching policy via the Cache-Control HTTP header. Cache-Control directives control who can cache the response, under which conditions, and for how long. "no-cache" the returned response can't be used to satisfy a subsequent request to the same URL without first checking with the server if the response has changed. ETag token and “no-cache” incurs a roundtrip to validate the cached response, but eliminates the download if the resource has not changed. "no-store" disallows the browser and all intermediate caches from storing any version of the returned response Thus, every time the user requests this URL, a request is sent to the server and a full response is downloaded. "max-age" specifies the maximum time in seconds that the fetched response is allowed to be reused from the time of the request. Web Caching:

12 Web Catching: Proxy Web Caching:

13 What is a Web Proxy (Web Cache)?
A proxy is a host which relays web access requests from clients Used when clients do not access the web directly Used for security, logging, accounting and performance Typically a Web cache is purchased and installed by an ISP. For example, a university might install a cache on its campus network and configure all of the campus browsers to point to the cache. browser proxy web Web Caching:

14 Web caches (proxy server)
goal: satisfy client request without involving origin server User sets browser: Web accesses via cache Browser sends all HTTP requests to cache If object is in cache: cache returns object else cache requests object from origin server, then returns object to client client proxy server HTTP request HTTP response origin Web Caching:

15 Web caches (proxy server)
The browser: establishes a TCP connection to the Web cache and sends an HTTP request for the object to the Web cache. The Web cache: checks to see if it has a copy of the object stored locally If it does: the Web cache returns the object within an HTTP response message to the client browser. No request from the original server is made Web Caching:

16 Web caches (proxy server)
If the Web cache does not have the object: The Web cache: opens a TCP connection to the origin server. then sends an HTTP request for the object into the cache-to-server TCP connection. Origin server After receiving this request, it sends the object within an HTTP response to the Web cache. When the Web cache receives the object: it stores a copy in its local storage and sends a copy, within an HTTP response message, to the client browser (over the existing TCP connection between the client browser and the Web cache). Web Caching:

17 Web Caches (proxy server)
Note that a cache is both a server and a client at the same time. When it receives requests from and sends responses to a browser, it is a server. When it sends requests to and receives responses from an origin server, it is a client. Web caching has seen deployment in the Internet for two reasons: First, a Web Cache can substantially reduce the response time for a client request, Second, Web Caches can substantially reduce traffic on an institution’s access link to the Internet (reducing costs). Web caches can substantially reduce Web traffic in the Internet as a whole, thereby improving performance for all applications. Web Caching:

18 Summary: Web Caching cache acts as both client and server
server for original requesting client client to origin server typically cache is installed by ISP (university, company, residential ISP) why Web caching? reduce response time for client request reduce traffic on an institution’s access link Internet dense with caches: enables “poor” content providers to effectively deliver content (so too does P2P file sharing) Web Caching:

19 If-modified-since: <date> If-modified-since: <date>
Conditional GET server client Goal: don’t send object if cache has up-to-date cached version no object transmission delay lower link utilization cache: specify date of cached copy in HTTP request If-modified-since: <date> server: response contains no object if cached copy is up-to- date: HTTP/ Not Modified HTTP request msg If-modified-since: <date> object not modified before <date> HTTP response HTTP/1.0 304 Not Modified HTTP request msg If-modified-since: <date> object modified after <date> HTTP response HTTP/ OK <data> Web Caching:


Download ppt "Web Caching? Web Caching:."

Similar presentations


Ads by Google