Cache? - PowerPoint PPT Presentation

1 / 27
About This Presentation
Title:

Cache?

Description:

PACS 06/21/14. 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 ... – PowerPoint PPT presentation

Number of Views:113
Avg rating:3.0/5.0
Slides: 28
Provided by: pacs152
Learn more at: https://PACSnet.org
Category:
Tags: cache | flash | memory | nand

less

Transcript and Presenter's Notes

Title: Cache?


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 datas original, more distant,
    slower, less expensive location.
  • A way to determine whether the cached copy is
    valid is important.

2
Cache Examples
  • The Zoo Photographer example
  • CPU Caching
  • Disk Caching
  • DNS Caching
  • Web Caching

3
CPU Cache
4
CPU Cache
Level Access Typical Technology Managed
Level Time Size Technology By
Registers 1-3 ns ?1 KB Custom CMOS Compiler
Level 1 Cache (on-chip) 2-8 ns 8 KB-128 KB SRAM Hardware
Level 2 Cache (off-chip) 5-12 ns 0.5 MB - 8 MB SRAM Hardware
Main Memory 10-60 ns 64 MB - 1 GB DRAM Operating System
Hard Disk 3,000,000 - 20 - 100 GB Magnetic Operating System/User
Hard Disk 10,000,000 ns 20 - 100 GB Magnetic Operating System/User
5
CPU Cache
6
CPU Cache
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
Disk Cache
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
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
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 doesnt 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
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 browsers 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
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 users 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
15
Web Caching
16
Web Caching
17
Web Caching
18
Web Caching
  • Apache Server Caching Guide http//httpd.apache.o
    rg/docs/2.2/caching.html
  • Apache Caching Header Guide http//httpd.apache.o
    rg/docs/2.2/mod/mod_expires.html
  • 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
Web Caching
  • If the responses headers tell the cache not to
    keep it, it wont.
  • If the request is authenticated or secure (i.e.,
    HTTPS), it wont 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
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
    its 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
  • ltFilesMatch "\.(flvicopdfavimovpptdocmp3wm
    vwav)"gt
  • ExpiresDefault A31536000
  • lt/FilesMatchgt
  • 1 WEEK - possible to be changed, unlikely
  • ltFilesMatch "\.(jpgjpegpnggifswf)"gt
  • ExpiresDefault A604800
  • lt/FilesMatchgt
  • 3 HOUR - core content, changes quickly
  • ltFilesMatch "\.(txtxmljscss)"gt
  • ExpiresDefault A10800
  • lt/FilesMatchgt
  • A means Access plus M means
    Modification plus

22
Web Caching
  • Using max-age headers
  • 1 YEAR
  • ltFilesMatch "\.(flvicopdfavimovpptdocmp3wm
    vwav)"gt
  • Header set Cache-Control "max-age31536000,
    public"
  • lt/FilesMatchgt
  • 1 WEEK
  • ltFilesMatch "\.(jpgjpegpnggifswf)"gt
  • Header set Cache-Control "max-age604800, public"
  • lt/FilesMatchgt
  • 3 HOUR
  • ltFilesMatch "\.(txtxmljscss)"gt
  • Header set Cache-Control "max-age10800"
  • lt/FilesMatchgt
  • NEVER CACHE - notice the extra directives
  • ltFilesMatch "\.(htmlhtmphpcgipl)"gt
  • Header set Cache-Control "max-age0, private,
    no-store, no-cache, must-revalidate"

23
Web Caching
  • Where do the cache related headers get set?
  • Meta tags in HTML documents (Pragma no-cache)
    are not effective. Theyre 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 131941 GMT
  • Server Apache/1.3.3 (Unix)
  • Cache-Control max-age3600, must-revalidate
  • Expires Fri, 30 Oct 1998 141941 GMT
  • Last-Modified Mon, 29 Jun 1998 022812 GMT
  • ETag "3e86-410-3596fbbc"
  • Content-Length 1040
  • Content-Type text/html

24
Web Caching
  • In .htaccess
  • ltIfModule mod_expires.cgt
  • ltFilesMatch "\.(csscss\.phpjsgifjpegjpgpng
    mp3pdfxml\.php)"gt
  • ExpiresActive On
  • ExpiresDefault "access plus 1 year"
  • Header append Cache-Control "must-revalidate,
    public"
  • lt/FilesMatchgt
  • lt/IfModulegt

25
Web Caching
  • In your PHP script
  • header("Cache-Control no-cache,
    must-revalidate") // HTTP/1.1
  • header("Expires Sat, 26 Jul 1997 050000 GMT")
    // Date in the past to force a new request
  • OR
  • if (page_cache)
  • header("Expires ".gmdate("D, d M Y His",
    pltime page_cache)." GMT")
  • header("Cache-Control must-revalidate,
    public")
  • header("Last-Modified ".gmdate("D, d M Y
    His", filemtime(__FILE__))." GMT")
  • // page_cache

26
Web Caching
  • Examine your site in Redbot.org to see what cache
    headers are being sent.
  • 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
Web Caching
  • Caching Tutorial for Web Authors and Webmasters
    https//www.mnot.net/cache_docs/
  • How To Optimize Your Site With HTTP Caching
    http//betterexplained.com/articles/how-to-optimiz
    e-your-site-with-http-caching/
Write a Comment
User Comments (0)
About PowerShow.com