29
Cache bonanza Harald Schult Ulriksen @hsulriksen http://aurum.no

Cache bonanza

Embed Size (px)

Citation preview

Page 1: Cache bonanza

Cache bonanzaHarald Schult Ulriksen

@hsulriksenhttp://aurum.no

Page 2: Cache bonanza
Page 3: Cache bonanza

HTTP Cache Output cache

Application cache

Page 4: Cache bonanza

RFC 7234 - HTTP/1.1 Caching

Page 5: Cache bonanza

RFC 7234 - HTTP/1.1 Caching

A stored response can be considered fresh if the response can be reused without validation

Page 6: Cache bonanza

RFC 7234 - HTTP/1.1 CachingAlthough caching is an entirely OPTIONAL feature of HTTP, it can be assumed that reusing a cached response is desirable and that such reuse is the default behavior when no requirement or local configuration prevents it. Therefore, HTTP cache requirements are focused on preventing a cache from either storing a non-reusable response or reusing a stored response inappropriately, rather than mandating that caches always store and reuse particular responses.

Page 7: Cache bonanza

RFC 7234 - HTTP/1.1 CachingFreshness

• s-max-age• max age• expires• heuristics

Page 8: Cache bonanza

RFC 7234 - HTTP/1.1 CachingFreshness

• s-max-age• max age• expires• heuristics

Last modified Last requested Now

Tid

Page 9: Cache bonanza

RFC 7234 - HTTP/1.1 CachingFreshness

• s-max-age• max age• expires• heuristics

Validation - RFC 7232

• Etag• Last-Modified

• If-none-match• If-modified-since

Page 10: Cache bonanza

RFC 7234 - HTTP/1.1 CachingLinker

• RFC 7234 - https://tools.ietf.org/html/rfc7234• RFC 7232 - https://tools.ietf.org/html/rfc7234• Mark Nottinham - https://www.mnot.net/cache_docs• Darrel Miller - http://

bizcoder.com/caching-is-hard-draw-me-a-picture• Jesse Wilson – https://

publicobject.com/2015/03/26/how-do-http-caching-heuristics-work

Page 11: Cache bonanza

Application cache• Local cache• Redis • Redis with msgpack•Distributed layered cache•With synchronization• Fun with Redis

Page 12: Cache bonanza

Local cache

Page 13: Cache bonanza

Demo

Page 14: Cache bonanza

Remote cache

Page 15: Cache bonanza

Remote cache

Page 16: Cache bonanza

Remote cache

Page 17: Cache bonanza

Redis• http://redis.io• Key value store + data structures• By Salvatore Sanfilippo / @antirez• Ansi C• Single threaded• Lua in server• Microsoft research port to windows – nuget redis-64• On Azure, AWS og Google cloud.

Page 18: Cache bonanza

Demo

Page 19: Cache bonanza

In production

Page 20: Cache bonanza

Layered distributed cacheApplication Local cache Remote cache Slow thing

Page 21: Cache bonanza

Demo

Page 22: Cache bonanza

Pub-sub12

3

4

1.Store data 2.Send publish notification3.Publish notification4.Get data

Page 23: Cache bonanza

Demo

Page 24: Cache bonanza

In production

Page 25: Cache bonanza

In production

Page 26: Cache bonanza

Other datastructures in RedisSearch for «An introduction to data types and abstractions»

• Key/Value• Lists• Hashsets• Set• Sorted set• Hyperloglog• Geospatial

Page 27: Cache bonanza

Lua scriptAtomisk operasjon. Ingen rollback. Kan lastes opp til server og kalles basert på hash.

Page 28: Cache bonanza

Add now-playing

Page 29: Cache bonanza

Read