Cache me outside - Umbraco Spark · Cache me outside ANTHONY DANG HEAD OF TECHNOLOGY, THE COGWORKS...

27
The Cogworks - UK’s Leading Umbraco Gold Partner thecogworks.com Cache me outside ANTHONY DANG HEAD OF TECHNOLOGY, THE COGWORKS

Transcript of Cache me outside - Umbraco Spark · Cache me outside ANTHONY DANG HEAD OF TECHNOLOGY, THE COGWORKS...

Page 1: Cache me outside - Umbraco Spark · Cache me outside ANTHONY DANG HEAD OF TECHNOLOGY, THE COGWORKS ... Partial Cache Output Cache / Donut Cache Custom Inline (method-level) Cache

The Cogworks - UK’s Leading Umbraco Gold Partnerthecogworks.com

Cache me outside

ANTHONY DANGHEAD OF TECHNOLOGY, THE COGWORKS

Page 2: Cache me outside - Umbraco Spark · Cache me outside ANTHONY DANG HEAD OF TECHNOLOGY, THE COGWORKS ... Partial Cache Output Cache / Donut Cache Custom Inline (method-level) Cache

The Cogworks - UK’s Leading Umbraco Gold Partnerthecogworks.com

Cache me outside. How ‘bout dat!

Page 3: Cache me outside - Umbraco Spark · Cache me outside ANTHONY DANG HEAD OF TECHNOLOGY, THE COGWORKS ... Partial Cache Output Cache / Donut Cache Custom Inline (method-level) Cache

The Cogworks - UK’s Leading Umbraco Gold Partnerthecogworks.com

Intro

● Cache Rational● Caching approaches

○ Partial Cache○ Output Cache / Donut Cache○ Custom Inline (method-level) Cache○ Redis○ Service Layer Cache○ CQRS○ Varnish / Fastly○ Cloudflare / Cloudfront○ CDNs

Page 4: Cache me outside - Umbraco Spark · Cache me outside ANTHONY DANG HEAD OF TECHNOLOGY, THE COGWORKS ... Partial Cache Output Cache / Donut Cache Custom Inline (method-level) Cache

The Cogworks - UK’s Leading Umbraco Gold Partnerthecogworks.com

Why Cache?

● Blazing fast UX● Limited bandwidth / API availability● Cost● Slow app

Page 5: Cache me outside - Umbraco Spark · Cache me outside ANTHONY DANG HEAD OF TECHNOLOGY, THE COGWORKS ... Partial Cache Output Cache / Donut Cache Custom Inline (method-level) Cache

The Cogworks - UK’s Leading Umbraco Gold Partnerthecogworks.com

Common Headaches

● Predictable Invalidation○ Multi-layer fallacy eg.

■ Data layer: 1min■ Service layer: 10min■ Presentation layer: 60min

● Security● Debugging● Always Enabled / Partially disabled

Page 6: Cache me outside - Umbraco Spark · Cache me outside ANTHONY DANG HEAD OF TECHNOLOGY, THE COGWORKS ... Partial Cache Output Cache / Donut Cache Custom Inline (method-level) Cache

The Cogworks - UK’s Leading Umbraco Gold Partnerthecogworks.com

Partial Caching

Cons● Cache invalidation● Hard to maintain

Page 7: Cache me outside - Umbraco Spark · Cache me outside ANTHONY DANG HEAD OF TECHNOLOGY, THE COGWORKS ... Partial Cache Output Cache / Donut Cache Custom Inline (method-level) Cache

The Cogworks - UK’s Leading Umbraco Gold Partnerthecogworks.com

Output Caching

● Controllers, Actions● Profiles

○ Not for Child Actions

Cons● Security

Page 8: Cache me outside - Umbraco Spark · Cache me outside ANTHONY DANG HEAD OF TECHNOLOGY, THE COGWORKS ... Partial Cache Output Cache / Donut Cache Custom Inline (method-level) Cache

The Cogworks - UK’s Leading Umbraco Gold Partnerthecogworks.com

Donut Cache

● Controllers, Actions● Profiles

Cons● Child actions● Nested partials● Hole punching => swiss cheese

Page 9: Cache me outside - Umbraco Spark · Cache me outside ANTHONY DANG HEAD OF TECHNOLOGY, THE COGWORKS ... Partial Cache Output Cache / Donut Cache Custom Inline (method-level) Cache

The Cogworks - UK’s Leading Umbraco Gold Partnerthecogworks.com

Umbraco Node Caching

● ID vs Node● Cache invalidation● Grid● Multi Node Tree Picker

Page 10: Cache me outside - Umbraco Spark · Cache me outside ANTHONY DANG HEAD OF TECHNOLOGY, THE COGWORKS ... Partial Cache Output Cache / Donut Cache Custom Inline (method-level) Cache

The Cogworks - UK’s Leading Umbraco Gold Partnerthecogworks.com

Umbraco Node Caching

20ms

Page 11: Cache me outside - Umbraco Spark · Cache me outside ANTHONY DANG HEAD OF TECHNOLOGY, THE COGWORKS ... Partial Cache Output Cache / Donut Cache Custom Inline (method-level) Cache

The Cogworks - UK’s Leading Umbraco Gold Partnerthecogworks.com

Umbraco Node Caching

● ?

Page 12: Cache me outside - Umbraco Spark · Cache me outside ANTHONY DANG HEAD OF TECHNOLOGY, THE COGWORKS ... Partial Cache Output Cache / Donut Cache Custom Inline (method-level) Cache

The Cogworks - UK’s Leading Umbraco Gold Partnerthecogworks.com

Custom Inline (method-level) Cache

● Granular control

Cons● Harder to understand● Code littering● Multi webheads● And….

Page 13: Cache me outside - Umbraco Spark · Cache me outside ANTHONY DANG HEAD OF TECHNOLOGY, THE COGWORKS ... Partial Cache Output Cache / Donut Cache Custom Inline (method-level) Cache

The Cogworks - UK’s Leading Umbraco Gold Partnerthecogworks.com

Custom Inline (method-level) Cache

Page 14: Cache me outside - Umbraco Spark · Cache me outside ANTHONY DANG HEAD OF TECHNOLOGY, THE COGWORKS ... Partial Cache Output Cache / Donut Cache Custom Inline (method-level) Cache

The Cogworks - UK’s Leading Umbraco Gold Partnerthecogworks.com

Custom Inline (method-level) Cache

● Unpredictable behaviour

Page 15: Cache me outside - Umbraco Spark · Cache me outside ANTHONY DANG HEAD OF TECHNOLOGY, THE COGWORKS ... Partial Cache Output Cache / Donut Cache Custom Inline (method-level) Cache

The Cogworks - UK’s Leading Umbraco Gold Partnerthecogworks.com

IService Cache Pattern with IoC

Original method

Page 16: Cache me outside - Umbraco Spark · Cache me outside ANTHONY DANG HEAD OF TECHNOLOGY, THE COGWORKS ... Partial Cache Output Cache / Donut Cache Custom Inline (method-level) Cache

The Cogworks - UK’s Leading Umbraco Gold Partnerthecogworks.com

Custom Service Cache Pattern

● Swappable in IoC container● Granular caching of services

Page 17: Cache me outside - Umbraco Spark · Cache me outside ANTHONY DANG HEAD OF TECHNOLOGY, THE COGWORKS ... Partial Cache Output Cache / Donut Cache Custom Inline (method-level) Cache

The Cogworks - UK’s Leading Umbraco Gold Partnerthecogworks.com

Redis

● External Caching service● Alternative to HttpRuntime

○ Multiple web heads

Page 18: Cache me outside - Umbraco Spark · Cache me outside ANTHONY DANG HEAD OF TECHNOLOGY, THE COGWORKS ... Partial Cache Output Cache / Donut Cache Custom Inline (method-level) Cache

The Cogworks - UK’s Leading Umbraco Gold Partnerthecogworks.com

Redis

Page 19: Cache me outside - Umbraco Spark · Cache me outside ANTHONY DANG HEAD OF TECHNOLOGY, THE COGWORKS ... Partial Cache Output Cache / Donut Cache Custom Inline (method-level) Cache

The Cogworks - UK’s Leading Umbraco Gold Partnerthecogworks.com

Varnish

● Cached HTTP Proxy ● Granular rules

Cons● Crazy configs https://bit.ly/2tTO7Bd● Linux command line● A point of failure

Page 20: Cache me outside - Umbraco Spark · Cache me outside ANTHONY DANG HEAD OF TECHNOLOGY, THE COGWORKS ... Partial Cache Output Cache / Donut Cache Custom Inline (method-level) Cache

The Cogworks - UK’s Leading Umbraco Gold Partnerthecogworks.com

Cloudflare & Cloudfront

● Sits outside your application● Remember to clear - UmbracoFlare● SLA’s & confusing UX?

Page 21: Cache me outside - Umbraco Spark · Cache me outside ANTHONY DANG HEAD OF TECHNOLOGY, THE COGWORKS ... Partial Cache Output Cache / Donut Cache Custom Inline (method-level) Cache

The Cogworks - UK’s Leading Umbraco Gold Partnerthecogworks.com

CDN

● UX● Assets● Clear by querystring

Cons● Custom deployment process

Page 22: Cache me outside - Umbraco Spark · Cache me outside ANTHONY DANG HEAD OF TECHNOLOGY, THE COGWORKS ... Partial Cache Output Cache / Donut Cache Custom Inline (method-level) Cache

The Cogworks - UK’s Leading Umbraco Gold Partnerthecogworks.com

Command Query Responsibility Segregation

“At its heart is the notion that you can use a different model to update information than the model you use to read information.” - Martin Fowler

● Page models > complexity than DB models● On save, construct a page model

Cons● Cache Invalidation is hard

Page 23: Cache me outside - Umbraco Spark · Cache me outside ANTHONY DANG HEAD OF TECHNOLOGY, THE COGWORKS ... Partial Cache Output Cache / Donut Cache Custom Inline (method-level) Cache

The Cogworks - UK’s Leading Umbraco Gold Partnerthecogworks.com

Debugging?● Turn it off!● Profiling

○ Ants○ Dot Trace

● Wrap suspicious code ● Monitor

○ Elmah.io ○ New Relic

Page 24: Cache me outside - Umbraco Spark · Cache me outside ANTHONY DANG HEAD OF TECHNOLOGY, THE COGWORKS ... Partial Cache Output Cache / Donut Cache Custom Inline (method-level) Cache

The Cogworks - UK’s Leading Umbraco Gold Partnerthecogworks.com

Which to choose?● Partial Cache● Output Cache● Donut Cache● HttpRuntime.Cache ● Redis● IService Layer with IoC● Varnish / Fastly● Cloudflare / Cloudfront● CDNs

Page 25: Cache me outside - Umbraco Spark · Cache me outside ANTHONY DANG HEAD OF TECHNOLOGY, THE COGWORKS ... Partial Cache Output Cache / Donut Cache Custom Inline (method-level) Cache

The Cogworks - UK’s Leading Umbraco Gold Partnerthecogworks.com

Considerations● Custom code => Code Debt

○ Only cache if you need to!● Multiple layers => multiple headaches● WAF

○ Azure Application Gateway >100USD○ Cloudflare >20 USD

● Why & What?○ Sitemap.xml?

● Cache purge failure

Page 26: Cache me outside - Umbraco Spark · Cache me outside ANTHONY DANG HEAD OF TECHNOLOGY, THE COGWORKS ... Partial Cache Output Cache / Donut Cache Custom Inline (method-level) Cache

The Cogworks - UK’s Leading Umbraco Gold Partnerthecogworks.com

Considerations - Multiple Layers

● Endpoint limits / throttling○ Custom Datalayer / Service IoC

● Tree crawling○ Custom Datalayer / Service IoC

● Better HTML response○ Donut caching

● Uptime availability / UX○ Varnish / Cloudfront

Page 27: Cache me outside - Umbraco Spark · Cache me outside ANTHONY DANG HEAD OF TECHNOLOGY, THE COGWORKS ... Partial Cache Output Cache / Donut Cache Custom Inline (method-level) Cache

The Cogworks - UK’s Leading Umbraco Gold Partnerthecogworks.com

Thanks@anthonydotnet

Elmah.io Promocode: umbracospark2019