54. Gateway Cache
Bob Backend
GET /foo
GET /foo Host: foo.com
Host: foo.com If-None-Match: abcdef012345
55. Gateway Cache
Bob Backend
GET /foo
GET /foo Host: foo.com
Host: foo.com If-None-Match: abcdef012345
304NotModified
56. Gateway Cache
Bob Backend
GET /foo
GET /foo Host: foo.com
Host: foo.com If-None-Match: abcdef012345
304NotModified
200OK
ETag:abcdef012345
57. Rails: fresh_when
class FooController Application
def show
@foo = Foo.find(params[:id])
fresh_when :etag = @foo,
:last_modified = @foo.updated_at.utc
end
end
58. Rails: stale?
class FooController Application
def show
@foo = Foo.find(params[:id])
modified = @foo.updated_at.utc
if stale?(:etag = @foo, :last_modified = modified)
respond_to do |wants|
# ... normal response processing
end
end
end
end
Pure ruby HTTP cache implementation.
This talk is not really about Rack::Cache.
Heroku understands HTTP caching.
What we're talking about when we say HTTP caching.
There's so many different caching systems.
Page caching, action caching, fragment caching, SQL caching, memcached.
*This* is what we're talking about
Wire level
Declarative.
Don't worry if this doesn't look familiar.
All caches adhere to the same basic rules for the most part.
Or browser cache.
People are most familiar with. When we think about HTTP caching, this is what comes to mind.
Bandwidth/Traffic Reduction.
Number of Clients served by the Cache.
I don’t want to talk about Client caches.
Many users behind a single cache
Also Known As “Reverse Proxy Cache”
The reasons have changed over time.
First server, client/browser, and web page
Things are good for, like, a year.
Ramble about research guys trading papers and linking to each other.
Explosive
Netscape goes public in 1995
State of the art
Roughly 2.3KB/s
Today, yahoo.com homepage is 388K - 2m48s
Other things: CGI just starting out. (Guestbooks, hit counters, search)
JavaScript - didn’t exist.
So what was the most important issue to solve?
Expires
Last-Modified
Cache-Control
ETag
Much more worried about load on backends.
Do less work.
I use ETag and If-None-Match. Last-Modified and If-Modified-Since.
I use ETag and If-None-Match. Last-Modified and If-Modified-Since.
I use ETag and If-None-Match. Last-Modified and If-Modified-Since.
I use ETag and If-None-Match. Last-Modified and If-Modified-Since.