http caching 101 and a bit of cachecow
DESCRIPTION
Discuss the basics of HTTP Caching according to HTTP 1.1 and how CacheCow library can implement these requirements for the server and the client.TRANSCRIPT
![Page 1: Http caching 101 and a bit of CacheCow](https://reader034.vdocument.in/reader034/viewer/2022042623/54c6f7024a795937038b45b9/html5/thumbnails/1.jpg)
HTTP Caching 101 and a bit of CacheCow Ali Kheyrollahi
![Page 2: Http caching 101 and a bit of CacheCow](https://reader034.vdocument.in/reader034/viewer/2022042623/54c6f7024a795937038b45b9/html5/thumbnails/2.jpg)
What you need for the Journey
![Page 3: Http caching 101 and a bit of CacheCow](https://reader034.vdocument.in/reader034/viewer/2022042623/54c6f7024a795937038b45b9/html5/thumbnails/3.jpg)
Let’s hear from Roy
“The problem with SOAP is that it tries to escape from the Web interface. It deliberately attempts to suck…”
![Page 4: Http caching 101 and a bit of CacheCow](https://reader034.vdocument.in/reader034/viewer/2022042623/54c6f7024a795937038b45b9/html5/thumbnails/4.jpg)
Caching – we use in ASP.NET
• Output caching
• HttpContext.Cache
• Memcached
• CacheCow.Server
• CacheCow.Client
• …
![Page 5: Http caching 101 and a bit of CacheCow](https://reader034.vdocument.in/reader034/viewer/2022042623/54c6f7024a795937038b45b9/html5/thumbnails/5.jpg)
Output caching
• A web server feature
• How to enable?
• User-mode vs. kernel-mode
•DEMO 1 -> netsh http show cachestate
•DEMO 2 -> perfmon
![Page 6: Http caching 101 and a bit of CacheCow](https://reader034.vdocument.in/reader034/viewer/2022042623/54c6f7024a795937038b45b9/html5/thumbnails/6.jpg)
HttpContext.Cache and Memcached
Key-Value store for storing anything you like
![Page 7: Http caching 101 and a bit of CacheCow](https://reader034.vdocument.in/reader034/viewer/2022042623/54c6f7024a795937038b45b9/html5/thumbnails/7.jpg)
HTTP Caching
• Server sets cache directives
•Clients or intermediaries store
• Technically every response by default is cacheable unless directives say otherwise – although …
•What do we cache?
We cache resources
![Page 8: Http caching 101 and a bit of CacheCow](https://reader034.vdocument.in/reader034/viewer/2022042623/54c6f7024a795937038b45b9/html5/thumbnails/8.jpg)
How to identify a resource?
URL http://www.example.com/this/that ?a=b&c=d
And any other header defined by Vary header sent by server
![Page 9: Http caching 101 and a bit of CacheCow](https://reader034.vdocument.in/reader034/viewer/2022042623/54c6f7024a795937038b45b9/html5/thumbnails/9.jpg)
Cache-Control - 1
private
public
Server Man-in the
middle Client
Server Man-in the
middle Client
✓
![Page 10: Http caching 101 and a bit of CacheCow](https://reader034.vdocument.in/reader034/viewer/2022042623/54c6f7024a795937038b45b9/html5/thumbnails/10.jpg)
Cache-Control - 2
no-store no-cache
![Page 11: Http caching 101 and a bit of CacheCow](https://reader034.vdocument.in/reader034/viewer/2022042623/54c6f7024a795937038b45b9/html5/thumbnails/11.jpg)
Cacheability – Lifecycle of resource
Fresh Stale Invalid
![Page 12: Http caching 101 and a bit of CacheCow](https://reader034.vdocument.in/reader034/viewer/2022042623/54c6f7024a795937038b45b9/html5/thumbnails/12.jpg)
Fresh
Cache-Control: max-age=3600
Expires: Tue, 11 Nov 2014 22:26:14 GMT
1
2
![Page 13: Http caching 101 and a bit of CacheCow](https://reader034.vdocument.in/reader034/viewer/2022042623/54c6f7024a795937038b45b9/html5/thumbnails/13.jpg)
Stale
Cache-Control: max-age=3600
Expires: Mon, 11 Nov 2013 22:26:14 GMT
1
2
![Page 14: Http caching 101 and a bit of CacheCow](https://reader034.vdocument.in/reader034/viewer/2022042623/54c6f7024a795937038b45b9/html5/thumbnails/14.jpg)
Validation
1
S T A L E
2 Cache-Control: no-cache
3 Cache-Control: must-revalidate
+ stale
![Page 15: Http caching 101 and a bit of CacheCow](https://reader034.vdocument.in/reader034/viewer/2022042623/54c6f7024a795937038b45b9/html5/thumbnails/15.jpg)
Validation – against ???
Last-Modified: Mon, 11 Nov 2013 22:26:14 GMT
1
ETag: “1edec-3e3073913b100”
2
“Resource Cache
State”
Server
![Page 16: Http caching 101 and a bit of CacheCow](https://reader034.vdocument.in/reader034/viewer/2022042623/54c6f7024a795937038b45b9/html5/thumbnails/16.jpg)
Demo
![Page 17: Http caching 101 and a bit of CacheCow](https://reader034.vdocument.in/reader034/viewer/2022042623/54c6f7024a795937038b45b9/html5/thumbnails/17.jpg)
Give-away! Connection:keep-alive Content-Length:43 Content-Type:image/gif Date:Fri, 15 Nov 2013 09:12:12 GMT Expires: -1
Can a proxy (man-in-the-middle) cache this resource? And why?
![Page 18: Http caching 101 and a bit of CacheCow](https://reader034.vdocument.in/reader034/viewer/2022042623/54c6f7024a795937038b45b9/html5/thumbnails/18.jpg)
… there is moar … eee…eeeeeeehhhhh!!!!!!
![Page 19: Http caching 101 and a bit of CacheCow](https://reader034.vdocument.in/reader034/viewer/2022042623/54c6f7024a795937038b45b9/html5/thumbnails/19.jpg)
CacheCow !!
![Page 20: Http caching 101 and a bit of CacheCow](https://reader034.vdocument.in/reader034/viewer/2022042623/54c6f7024a795937038b45b9/html5/thumbnails/20.jpg)
CacheCow
Looks after caching so you don’t have to
Has client and server components (You need client if your client is .NET)
1
2
3 You can choose from (or build) from a range of soft or persistent storages
4 Remember “cache state” gets stored on server while “resources” (or responses) themselves get stored on the client
![Page 21: Http caching 101 and a bit of CacheCow](https://reader034.vdocument.in/reader034/viewer/2022042623/54c6f7024a795937038b45b9/html5/thumbnails/21.jpg)
CacheCow.Server
1
2
![Page 22: Http caching 101 and a bit of CacheCow](https://reader034.vdocument.in/reader034/viewer/2022042623/54c6f7024a795937038b45b9/html5/thumbnails/22.jpg)
CacheCow.Server (setting cache
control)
NOT SURE I WANNA DO THAT!
![Page 23: Http caching 101 and a bit of CacheCow](https://reader034.vdocument.in/reader034/viewer/2022042623/54c6f7024a795937038b45b9/html5/thumbnails/23.jpg)
CacheCow.Server (attribute-based)
1
2
![Page 24: Http caching 101 and a bit of CacheCow](https://reader034.vdocument.in/reader034/viewer/2022042623/54c6f7024a795937038b45b9/html5/thumbnails/24.jpg)
CacheCow.Server (storage)
• In-memory (default)
• Memcached
• Memcached 1.2
• MongoDB
• RavenDB
• SQL Server
• Build your own (implement an interface)
![Page 25: Http caching 101 and a bit of CacheCow](https://reader034.vdocument.in/reader034/viewer/2022042623/54c6f7024a795937038b45b9/html5/thumbnails/25.jpg)
CacheCow.Client Turns HttpClient’s caching from zero to hero – like a browser
Request does not even touch the network If you have a fresh cache of the resource
1
2
3 Does all that conditional validation on GET and PUT so you don’t have to
4 You can choose from (or build) from a range of soft or persistent storages
![Page 26: Http caching 101 and a bit of CacheCow](https://reader034.vdocument.in/reader034/viewer/2022042623/54c6f7024a795937038b45b9/html5/thumbnails/26.jpg)
CacheCow.Client (setup)
1
2
![Page 27: Http caching 101 and a bit of CacheCow](https://reader034.vdocument.in/reader034/viewer/2022042623/54c6f7024a795937038b45b9/html5/thumbnails/27.jpg)
WHO CAN GUESS THE RESPONSE???
CacheCow.Client (example)
![Page 28: Http caching 101 and a bit of CacheCow](https://reader034.vdocument.in/reader034/viewer/2022042623/54c6f7024a795937038b45b9/html5/thumbnails/28.jpg)
CacheCow.Server (storage)
• In-memory (default)
• Memcached
• Memcached 1.2
• Redis
• File
• SQL Server
• Build your own (implement an interface)
![Page 29: Http caching 101 and a bit of CacheCow](https://reader034.vdocument.in/reader034/viewer/2022042623/54c6f7024a795937038b45b9/html5/thumbnails/29.jpg)
Questions??