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

Preview:

Citation preview

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

Cache me outside

ANTHONY DANGHEAD OF TECHNOLOGY, THE COGWORKS

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

Cache me outside. How ‘bout dat!

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

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

Why Cache?

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

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

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

Partial Caching

Cons● Cache invalidation● Hard to maintain

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

Output Caching

● Controllers, Actions● Profiles

○ Not for Child Actions

Cons● Security

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

Donut Cache

● Controllers, Actions● Profiles

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

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

Umbraco Node Caching

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

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

Umbraco Node Caching

20ms

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

Umbraco Node Caching

● ?

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….

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

Custom Inline (method-level) Cache

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

Custom Inline (method-level) Cache

● Unpredictable behaviour

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

IService Cache Pattern with IoC

Original method

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

Custom Service Cache Pattern

● Swappable in IoC container● Granular caching of services

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

Redis

● External Caching service● Alternative to HttpRuntime

○ Multiple web heads

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

Redis

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

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

Cloudflare & Cloudfront

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

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

CDN

● UX● Assets● Clear by querystring

Cons● Custom deployment process

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

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

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

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

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

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

Thanks@anthonydotnet

Elmah.io Promocode: umbracospark2019

Recommended