Top Banner
Caching Go big or go home Harald Schult Ulriksen @hsulriksen
28

Caching go big or go home - ndc 2016

Jan 22, 2018

Download

Software

Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Caching   go big or go home - ndc 2016

CachingGo big or go home

Harald Schult Ulriksen

@hsulriksen

Page 2: Caching   go big or go home - ndc 2016
Page 3: Caching   go big or go home - ndc 2016

HTTP CacheOutput

cache

Application

cache

Page 4: Caching   go big or go home - ndc 2016

RFC 7234 - HTTP/1.1 Caching

Page 5: Caching   go big or go home - ndc 2016

RFC 7234 - HTTP/1.1 Caching

A stored response can be considered fresh

if the response can be reused without validation

Page 6: Caching   go big or go home - ndc 2016

RFC 7234 - HTTP/1.1 Caching

Although 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: Caching   go big or go home - ndc 2016

RFC 7234 - HTTP/1.1 Caching

Freshness

• s-max-age

• max age

• Expires

• heuristics

Page 8: Caching   go big or go home - ndc 2016

RFC 7234 - HTTP/1.1 Caching

Freshness

• s-max-age

• max age

• Expires

• heuristics

Last modified Last requested Now

Tid

Page 9: Caching   go big or go home - ndc 2016

RFC 7234 - HTTP/1.1 Caching

Freshness

• s-max-age

• max age

• Expires

• heuristics

Validation - RFC 7232

• Etag

• Last-Modified

• If-none-match

• If-modified-since

Page 10: Caching   go big or go home - ndc 2016

RFC 7234 - HTTP/1.1 Caching

Links

• RFC 7234 - https://tools.ietf.org/html/rfc7234

• RFC 7232 - https://tools.ietf.org/html/rfc7234

• Mark Nottingham - 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: Caching   go big or go home - ndc 2016

Application cache

• ASP.NET Core (or Microsoft.extensions.caching)

• Local cache

• Redis

• Redis with msgpack

• Distributed layered cache

• With synchronization

Page 12: Caching   go big or go home - ndc 2016

Microsoft.Extensions.Caching

Page 13: Caching   go big or go home - ndc 2016

Microsoft.Extensions.Caching

IMemoryCache

• Powered by dictionary

• Supports callback oneviction.

• Has priority on items in cache

• Compacts on GC Gen2

Page 14: Caching   go big or go home - ndc 2016

Microsoft.Extensions.Caching

IMemoryCache

• Powered by dictionary

• Supports callback oneviction.

• Has priority on items in cache

• Compacts on GC Gen2

IDistributedCache

• MemoryCache

• Redis

• SQL Server

• You do the serialization

Page 15: Caching   go big or go home - ndc 2016

Local cache

Page 16: Caching   go big or go home - ndc 2016

Demo

Page 17: Caching   go big or go home - ndc 2016

Remote cache

Page 18: Caching   go big or go home - ndc 2016

Remote cache

Page 19: Caching   go big or go home - ndc 2016

Remote cache

Page 20: Caching   go big or go home - ndc 2016

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 21: Caching   go big or go home - ndc 2016

Demo

Page 22: Caching   go big or go home - ndc 2016

In production

Page 23: Caching   go big or go home - ndc 2016

Layered distributed cache

Application Local cache Remote cache Slow thing

Page 24: Caching   go big or go home - ndc 2016

Demo

Page 25: Caching   go big or go home - ndc 2016

Pub-sub

1

2

3

4

1.Store data

2.Send publish notification

3.Publish notification

4.Get data

Page 26: Caching   go big or go home - ndc 2016

Demo

Page 27: Caching   go big or go home - ndc 2016

In production

Page 28: Caching   go big or go home - ndc 2016

In production