How to make cache work for you

Sergey Chernyshev

New York, NY

December 10th, 2009

December '09 NY Web Performance Meetup

What Is Cache?

Cache Layers

Back-end

SQL Query Cache

Fun facts for MySQL query cache

App Data Cache

Generic cache in your app - tons of different tools

App Data Cache: File System

App Data Cache: Key-Value Store

Huge associative array persisted across requests

$memcache = new Memcache;
$memcache->connect('localhost', 11211)
	or die ("Can't connect");

$val = $memcache->get('hardtocompute');

if ($val === FALSE) {
	$val = computeThisHardThing();
	$memcache->set($val);
}

echo "This one is hard to get, but we cache it: $val";

memcached, APC, Redis, Tokyo Cabinet / Tyrant ... even Amazon S3

Key-value interface can be abstracted (Zend_Cache)

App Data Cache: Conclusion

Reverse Cache Proxies

Client

Rule 1

Amazon Waterfall

Use Browser Cache

HTML5 Application Cache

HTML5 Application Cache

On HTML page
<!DOCTYPE HTML>
<html manifest="my.cache.manifest">
...
Manifest file (Content-type: text/cache-manifest)
CACHE MANIFEST
index.html
help.html
style/default.css
images/logo.png
images/backgound.png

HTML5 Local Storage

HTML5 Local Storage

localStorage.setItem(key, value);
localStorage.getItem(key);
localStorage.removeItem(key);

localStorage['key'] = value;
localStorage.key = value;

localStorage.length;
localStorage.clear();

Conclusion

More info

About these slides

These slides use an HTML presentation tool Slidy.

They are valid XHTML document with rich metadata embedded using RDFa.

Valid XHTML + RDFa Extract RDF from RDFa on this page

Photos used

"Server Rack" photo by Jamison Judd

"Web Browsers 2009 (Map)" photo by tedion

Licensing & Attribution

How to make cache work for you by Sergey Chernyshev
is licensed under a Creative Commons Attribution 3.0 United States License.
Permissions beyond the scope of this license available here.

Creative Commons License