Cache is king

17

Transcript of Cache is king

Page 1: Cache is king
Page 2: Cache is king

Cache

Maciej Mendrela

Page 3: Cache is king

<url scheme>://<host>:<port>/<path>?query/#<frag>

uniform resource locator

Page 4: Cache is king

(start line) GET /BUILD/ASSETS/IMAGES/LOGO.PNG HTTP/1.1

HOST: WWW.EDRONE.ME 80

http://edrone.me/build/assets/images/logo.png

Page 5: Cache is king

MIME TYPE

application/javascript

Page 6: Cache is king

Request message

[method] [url] [version][headers]

[body]

Page 7: Cache is king

Full requestGET / HTTP/1.1Host: server.comConnection: keep-aliveUser-Agent: Mozilla/5.0(Windows NT 6.1; WOW64) Chrome/16.0.912.75 Safari/535.7Accept : text/html, application/xhtml+xml,application/xml;=0.9,*/*;q=0.8Referer : http://www.google.com/url?&q=edroneAccept-Encoding: gzip,deflate,sdchAccept-Language: en-US,en;q=0.8Accept-Charset: ISO-8859-1,uft-8;q=0.7,*;q=0.3

Page 8: Cache is king

Response message

[version] [status] [reason][headers]

[body]

Page 9: Cache is king

Full responseHTTP/1.1 200 OKCache-Control: privateContent-Type: text/html, charset=utf-8Server: Microsoft-IIS/7.0X-AspNet-Version: 2.0.50727X-Powered-By: ASP.NETDate: Sat, 14 Feb 2003 04:00:08 GMTContent-Lenght:17151

<html>...content

</html>

Page 10: Cache is king

Status codes categories

Range

•100-199•200-299•300-399•400-499•500-599

Category

•Informational•Successful•Redirection•Client Error•Server Error

Page 11: Cache is king

Popular one’s

Code/Reason

•200/OK•301/Moved Permanently•302/Moved Temporaily•304/Not Modifed•400/Bad Request •401/Unauthoized•403/Forbidden•404/Not found •500/Internal Server Error•503/Service Unavailable

Description

•Success!•Resource moved,don’t check here again•Resource moved, but check here again•Resource hasn’t changed since last retrival•Bad syntax?•Client might need to authenticate•Refused access•Resource doesn’t exist•Something went wrong during processing •Server will not recive the request

Page 12: Cache is king

Cache-Control

Page 13: Cache is king

Publicvs

Private

Page 14: Cache is king

Max-Age = 0vs

No-Cache

Page 15: Cache is king

Conditional request headers•Expect

•If-Match

•If-Modified-Since

•If-None-Match

•If-Range

•If-Unmodified-Since

•Range

•Allows client to list server behaviors that it requires for a request•Gets the document if the entity tag matches the current entity tag for the document•Restricts the request unless the resources has been modified since the specified date •Gets the document if the entity tags supplied do not match those of the current document•Allows a conditional request for a range of a document

•Restricts the request unless the resource has not been modified since the specified date•Request a specific range of a resource, if the server support range request

Page 16: Cache is king

Apache modules

mod_expires

•ExpiresActive On •ExpiresByType image/jpg "access plus 1 year" •ExpiresByType image/jpeg "access plus 1 year„•ExpiresByType text/css "access plus 1 month„•ExpiresByType application/pdf "access plus 1 month" •ExpiresByType text/x-javascript "access plus 1 month" •ExpiresByType application/x-shockwave-flash "access plus 1 month" •ExpiresByType image/x-icon "access plus 1 year„•ExpiresDefault "access plus 2 days"

mod_headers

•<Files *.php> •Header set Cache-Control public,max-age=3600 </Files> •<Files *.xml> •Header set Cache-Control "no-cache, no-store, must-revalidate, max-age=0" •</Files>

Page 17: Cache is king

Thank You!