Presentation is loading. Please wait.

Presentation is loading. Please wait.

PACS – 06/21/14 1 Cache? What is caching? A way to increase the average rate of a process by preferentially using a copy of data in a faster, closer, probably.

Similar presentations

Presentation on theme: "PACS – 06/21/14 1 Cache? What is caching? A way to increase the average rate of a process by preferentially using a copy of data in a faster, closer, probably."— Presentation transcript:

1 PACS – 06/21/14 1 Cache? What is caching? A way to increase the average rate of a process by preferentially using a copy of data in a faster, closer, probably more expensive location instead of the data’s original, more distant, slower, less expensive location. A way to determine whether the cached copy is valid is important.

2 PACS – 06/21/14 2 Cache Examples “The Zoo Photographer” example CPU Caching Disk Caching DNS Caching Web Caching

3 PACS – 06/21/14 3 CPU Cache

4 PACS – 06/21/14 4 CPU Cache Level AccessTypical Technology Managed TimeSizeBy Registers1-3 ns?1 KB Custom CMOS Compiler Level 1 Cache (on-chip) 2-8 ns8 KB-128 KBSRAMHardware Level 2 Cache (off-chip) 5-12 ns0.5 MB - 8 MBSRAMHardware Main Memory10-60 ns64 MB - 1 GBDRAMOperating System Hard Disk 3,000,000 - 20 - 100 GBMagnetic Operating System/User 10,000,000 ns

5 PACS – 06/21/14 5 CPU Cache

6 PACS – 06/21/14 6 CPU Cache

7 PACS – 06/21/14 7 Disk Caching Traditional Disk Cache is actually a disk buffer. It marries the faster bus timing with the slower rotating disk timing. Seagate Laptop and Ultra Mobile SSHDs integrate NAND flash with traditional hard drive storage to create a hybrid drive with the speed of solid state and the capacity of a hard drive. Boots Windows 7 up to 35% faster. Programs launch faster. Installs and works like a typical hard drive – no special device drivers needed Utilizes solid-state NAND flash and hard drive capacity for unmatched data integrity and reliability

8 PACS – 06/21/14 8 Disk Cache

9 PACS – 06/21/14 9 DNS Caching First request for a domain name: Each DNS server saves the results of each request along with an expiration time (TTL).

10 PACS – 06/21/14 10 DNS Cache Second request for the same domain name: If the cached value is valid, IP can be returned without further lookups. Clients also normally cache DNS results. In that case, no request to a DNS server is needed.

11 PACS – 06/21/14 11 Web Caching Why worry about speed? Users hate waiting! The browser save copies of images, stylesheets, javascript or the HTML. The next time the user needs that same resource for the same or a different web page the browser doesn’t have to download the file again. Fewer downloads means a faster, happier site. All browsers have cache areas available with sizes that can be controlled. There has to be a mechanism to allow for changed files on the server. Proxy servers will usually cache files to improve performance for their respective users.

12 PACS – 06/21/14 12 Web Caching Browsers use multiple methods of accessing a cached file depending on what the server supplied when the file was initially downloaded: Last-Modified – asks the server to decide based on the date of the browser’s copy. If-None-Match – asks the server to decide based on a unique characteristic of the file, like a hash. Expires – the browser will not ask the server if time is prior to the expiration time of the cached file. Max-age – like Expires but the server gives the browser a relative time rather than an absolute time when the file was first served. Different browsers may use any or all of the above approaches.

13 PACS – 06/21/14 13 Web Caching Other cache related headers: Cache-control: public means the cached version can be saved by proxies and other intermediate servers, where everyone can see it. Cache-control: private means the file is different for different users (such as their personal homepage). The user’s private browser can cache it, but not public proxies. Cache-control: no-cache means the file should not be cached. This is useful for things like search results where the URL appears the same but the content may change.

14 Web Caching PACS – 06/21/1414

15 Web Caching PACS – 06/21/1415

16 Web Caching PACS – 06/21/1416

17 Web Caching PACS – 06/21/1417

18 PACS – 06/21/14 18 Web Caching Apache Server Caching Guide: Apache Caching Header Guide: The general format for setting headers is File types to match Header / Expiration to set A general tip: the less a resource changes (images, pdfs, etc.) the longer you should cache it. If it never changes (every version has a different URL) then cache it for as long as you can (i.e. a year)!

19 PACS – 06/21/14 19 Web Caching If the response’s headers tell the cache not to keep it, it won’t. If the request is authenticated or secure (i.e., HTTPS), it won’t be cached. A cached representation is considered fresh (that is, able to be sent to a client without checking with the origin server) if: It has an expiry time or other age-controlling header set, and is still within the fresh period, or If the cache has seen the representation recently, and it was modified relatively long ago. Fresh representations are served directly from the cache, without checking with the origin server.

20 PACS – 06/21/14 20 Web Caching If a representation is stale, the origin server will be asked to validate it, or tell the cache whether the copy that it has is still good. Under certain circumstances — for example, when it’s disconnected from a network — a cache can serve stale responses without checking with the origin server. If no validator (an ETag or Last-Modified header) is present on a response, and it doesn't have any explicit freshness information, it will usually - but not always - be considered uncacheable.

21 Web Caching Using Expires Headers ExpiresActive On ExpiresDefault A0 # 1 YEAR - doesn't change often ExpiresDefault A31536000 # 1 WEEK - possible to be changed, unlikely ExpiresDefault A604800 # 3 HOUR - core content, changes quickly ExpiresDefault A10800 “A” means “Access plus…”; “M” means “Modification plus…” PACS – 06/21/1421

22 Web Caching Using max-age headers: # 1 YEAR Header set Cache-Control "max-age=31536000, public" # 1 WEEK Header set Cache-Control "max-age=604800, public" # 3 HOUR Header set Cache-Control "max-age=10800" # NEVER CACHE - notice the extra directives Header set Cache-Control "max-age=0, private, no-store, no-cache, must-revalidate" PACS – 06/21/1422

23 PACS – 06/21/14 23 Web Caching Where do the cache related headers get set? Meta tags in HTML documents (Pragma: no-cache) are not effective. They’re only honored by few browsers and never by proxy servers. They should be set in HTTP headers. A typical complete set of headers might be: HTTP/1.1 200 OK Date: Fri, 30 Oct 1998 13:19:41 GMT Server: Apache/1.3.3 (Unix) Cache-Control: max-age=3600, must-revalidate Expires: Fri, 30 Oct 1998 14:19:41 GMT Last-Modified: Mon, 29 Jun 1998 02:28:12 GMT ETag: "3e86-410-3596fbbc" Content-Length: 1040 Content-Type: text/html

24 Web Caching In.htaccess: ExpiresActive On ExpiresDefault "access plus 1 year" Header append Cache-Control "must-revalidate, public" PACS – 06/21/1424

25 Web Caching In your PHP script: header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1 header("Expires: Sat, 26 Jul 1997 05:00:00 GMT"); // Date in the past to force a new request OR if ($page_cache) { header("Expires: ".gmdate("D, d M Y H:i:s", $pltime + $page_cache)." GMT"); header("Cache-Control: must-revalidate, public"); header("Last-Modified: ".gmdate("D, d M Y H:i:s", filemtime(__FILE__))." GMT"); } // $page_cache PACS – 06/21/1425

26 PACS – 06/21/14 26 Web Caching Examine your site in to see what cache headers are being Use Firebug (or Live HTTP Headers addon) with Firefox to see requests and responses to page accesses. Ctrl-F5 will tell the IE & FF browsers to ignore any cached files and request a fresh copy of the page.

27 PACS – 06/21/14 27 Web Caching Caching Tutorial for Web Authors and Webmasters: How To Optimize Your Site With HTTP Caching: -to-optimize-your-site-with-http- caching/ -to-optimize-your-site-with-http- caching/

Download ppt "PACS – 06/21/14 1 Cache? What is caching? A way to increase the average rate of a process by preferentially using a copy of data in a faster, closer, probably."

Similar presentations

Ads by Google