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
HTTP Caching 101 and a bit of CacheCow Ali Kheyrollahi
What you need for the Journey
Let’s hear from Roy
“The problem with SOAP is that it tries to escape from the Web interface. It deliberately attempts to suck…”
Caching – we use in ASP.NET
• Output caching
• HttpContext.Cache
• Memcached
• CacheCow.Server
• CacheCow.Client
• …
Output caching
• A web server feature
• How to enable?
• User-mode vs. kernel-mode
•DEMO 1 -> netsh http show cachestate
•DEMO 2 -> perfmon
HttpContext.Cache and Memcached
Key-Value store for storing anything you like
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
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
Cache-Control - 1
private
public
Server Man-in the
middle Client
Server Man-in the
middle Client
✓
Cache-Control - 2
no-store no-cache
Cacheability – Lifecycle of resource
Fresh Stale Invalid
Fresh
Cache-Control: max-age=3600
Expires: Tue, 11 Nov 2014 22:26:14 GMT
1
2
Stale
Cache-Control: max-age=3600
Expires: Mon, 11 Nov 2013 22:26:14 GMT
1
2
Validation
1
S T A L E
2 Cache-Control: no-cache
3 Cache-Control: must-revalidate
+ stale
Validation – against ???
Last-Modified: Mon, 11 Nov 2013 22:26:14 GMT
1
ETag: “1edec-3e3073913b100”
2
“Resource Cache
State”
Server
Demo
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?
… there is moar … eee…eeeeeeehhhhh!!!!!!
CacheCow !!
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
CacheCow.Server
1
2
CacheCow.Server (setting cache
control)
NOT SURE I WANNA DO THAT!
CacheCow.Server (attribute-based)
1
2
CacheCow.Server (storage)
• In-memory (default)
• Memcached
• Memcached 1.2
• MongoDB
• RavenDB
• SQL Server
• Build your own (implement an interface)
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
CacheCow.Client (setup)
1
2
WHO CAN GUESS THE RESPONSE???
CacheCow.Client (example)
CacheCow.Server (storage)
• In-memory (default)
• Memcached
• Memcached 1.2
• Redis
• File
• SQL Server
• Build your own (implement an interface)
Questions??