http caching 101 and a bit of cachecow

29
HTTP Caching 101 and a bit of CacheCow Ali Kheyrollahi

Upload: ali-kheyrollahi

Post on 27-Jan-2015

110 views

Category:

Software


4 download

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

HTTP Caching 101 and a bit of CacheCow Ali Kheyrollahi

Page 2: Http caching 101 and a bit of CacheCow

What you need for the Journey

Page 3: Http caching 101 and a bit of CacheCow

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

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

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

HttpContext.Cache and Memcached

Key-Value store for storing anything you like

Page 7: Http caching 101 and a bit of CacheCow

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

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

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

Cache-Control - 2

no-store no-cache

Page 11: Http caching 101 and a bit of CacheCow

Cacheability – Lifecycle of resource

Fresh Stale Invalid

Page 12: Http caching 101 and a bit of CacheCow

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

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

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

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

Demo

Page 17: Http caching 101 and a bit of CacheCow

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

… there is moar … eee…eeeeeeehhhhh!!!!!!

Page 19: Http caching 101 and a bit of CacheCow

CacheCow !!

Page 20: Http caching 101 and a bit of 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

Page 21: Http caching 101 and a bit of CacheCow

CacheCow.Server

1

2

Page 22: Http caching 101 and a bit of CacheCow

CacheCow.Server (setting cache

control)

NOT SURE I WANNA DO THAT!

Page 23: Http caching 101 and a bit of CacheCow

CacheCow.Server (attribute-based)

1

2

Page 24: Http caching 101 and a bit of CacheCow

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

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

CacheCow.Client (setup)

1

2

Page 27: Http caching 101 and a bit of CacheCow

WHO CAN GUESS THE RESPONSE???

CacheCow.Client (example)

Page 28: Http caching 101 and a bit of CacheCow

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

Questions??